* Information associated by mono with LLVM modules.
*/
typedef struct {
- LLVMModuleRef module;
+ LLVMModuleRef lmodule;
LLVMValueRef throw_icall, rethrow, match_exc, throw_corlib_exception, resume_eh;
GHashTable *llvm_types;
LLVMValueRef got_var;
MonoCompile *cfg;
LLVMValueRef lmethod;
- MonoLLVMModule *lmodule;
- LLVMModuleRef module;
+ MonoLLVMModule *module;
+ LLVMModuleRef lmodule;
BBInfo *bblocks;
int sindex, default_index, ex_index;
LLVMBuilderRef builder;
static void emit_dbg_loc (EmitContext *ctx, LLVMBuilderRef builder, const unsigned char *cil_code);
static LLVMValueRef emit_dbg_subprogram (EmitContext *ctx, MonoCompile *cfg, LLVMValueRef method, const char *name);
-static void emit_dbg_info (MonoLLVMModule *lmodule, const char *filename, const char *cu_name);
+static void emit_dbg_info (MonoLLVMModule *module, const char *filename, const char *cu_name);
/*
* IntPtrType:
}
static LLVMTypeRef
-create_llvm_type_for_type (MonoLLVMModule *lmodule, MonoClass *klass)
+create_llvm_type_for_type (MonoLLVMModule *module, MonoClass *klass)
{
int i, size, nfields, esize;
LLVMTypeRef *eltypes;
}
name = mono_type_full_name (&klass->byval_arg);
- ltype = LLVMStructCreateNamed (lmodule->context, name);
+ ltype = LLVMStructCreateNamed (module->context, name);
LLVMStructSetBody (ltype, eltypes, size, FALSE);
g_free (eltypes);
g_free (name);
if (klass->enumtype)
return type_to_llvm_type (ctx, mono_class_enum_basetype (klass));
- ltype = (LLVMTypeRef)g_hash_table_lookup (ctx->lmodule->llvm_types, klass);
+ ltype = (LLVMTypeRef)g_hash_table_lookup (ctx->module->llvm_types, klass);
if (!ltype) {
- ltype = create_llvm_type_for_type (ctx->lmodule, klass);
- g_hash_table_insert (ctx->lmodule->llvm_types, klass, ltype);
+ ltype = create_llvm_type_for_type (ctx->module, klass);
+ g_hash_table_insert (ctx->module->llvm_types, klass, ltype);
}
return ltype;
}
sprintf (bb_name_buf, "EH_CLAUSE%d_BB%d", clause_index, bb->block_num);
bb_name = bb_name_buf;
} else if (bb->block_num < 256) {
- if (!ctx->lmodule->bb_names) {
- ctx->lmodule->bb_names_len = 256;
- ctx->lmodule->bb_names = g_new0 (char*, ctx->lmodule->bb_names_len);
+ if (!ctx->module->bb_names) {
+ ctx->module->bb_names_len = 256;
+ ctx->module->bb_names = g_new0 (char*, ctx->module->bb_names_len);
}
- if (!ctx->lmodule->bb_names [bb->block_num]) {
+ if (!ctx->module->bb_names [bb->block_num]) {
char *n;
n = g_strdup_printf ("BB%d", bb->block_num);
mono_memory_barrier ();
- ctx->lmodule->bb_names [bb->block_num] = n;
+ ctx->module->bb_names [bb->block_num] = n;
}
- bb_name = ctx->lmodule->bb_names [bb->block_num];
+ bb_name = ctx->module->bb_names [bb->block_num];
} else {
sprintf (bb_name_buf, "BB%d", bb->block_num);
bb_name = bb_name_buf;
}
if (!ctx->llvm_only && cinfo && cinfo->rgctx_arg) {
cinfo->rgctx_arg_pindex = pindex;
- param_types [pindex] = ctx->lmodule->ptr_type;
+ param_types [pindex] = ctx->module->ptr_type;
pindex ++;
}
if (cinfo && cinfo->imt_arg) {
cinfo->imt_arg_pindex = pindex;
- param_types [pindex] = ctx->lmodule->ptr_type;
+ param_types [pindex] = ctx->module->ptr_type;
pindex ++;
}
if (vretaddr) {
if (ctx->llvm_only && cinfo && cinfo->rgctx_arg) {
/* Pass the rgctx as the last argument */
cinfo->rgctx_arg_pindex = pindex;
- param_types [pindex] = ctx->lmodule->ptr_type;
+ param_types [pindex] = ctx->module->ptr_type;
pindex ++;
}
cfg->patch_info = ji;
got_offset = mono_aot_get_got_offset (cfg->patch_info);
- ctx->lmodule->max_got_offset = MAX (ctx->lmodule->max_got_offset, got_offset);
+ ctx->module->max_got_offset = MAX (ctx->module->max_got_offset, got_offset);
/*
* If the got slot is shared, it means its initialized when the aot image is loaded, so we don't need to
* explicitly initialize it.
indexes [0] = LLVMConstInt (LLVMInt32Type (), 0, FALSE);
indexes [1] = LLVMConstInt (LLVMInt32Type (), (gssize)got_offset, FALSE);
- got_entry_addr = LLVMBuildGEP (builder, ctx->lmodule->got_var, indexes, 2, "");
+ got_entry_addr = LLVMBuildGEP (builder, ctx->module->got_var, indexes, 2, "");
switch (type) {
case MONO_PATCH_INFO_INTERNAL_METHOD:
if (callee_name) {
/* Directly callable */
// FIXME: Locking
- callee = (LLVMValueRef)g_hash_table_lookup (ctx->lmodule->direct_callables, callee_name);
+ callee = (LLVMValueRef)g_hash_table_lookup (ctx->module->direct_callables, callee_name);
if (!callee) {
- callee = LLVMAddFunction (ctx->module, callee_name, llvm_sig);
+ callee = LLVMAddFunction (ctx->lmodule, callee_name, llvm_sig);
LLVMSetVisibility (callee, LLVMHiddenVisibility);
- g_hash_table_insert (ctx->lmodule->direct_callables, (char*)callee_name, callee);
+ g_hash_table_insert (ctx->module->direct_callables, (char*)callee_name, callee);
} else {
g_free (callee_name);
}
mono_add_patch_info (ctx->cfg, 0, type, data);
// FIXME: Locking
- callee = (LLVMValueRef)g_hash_table_lookup (ctx->lmodule->plt_entries, callee_name);
+ callee = (LLVMValueRef)g_hash_table_lookup (ctx->module->plt_entries, callee_name);
if (!callee) {
- callee = LLVMAddFunction (ctx->module, callee_name, llvm_sig);
+ callee = LLVMAddFunction (ctx->lmodule, callee_name, llvm_sig);
LLVMSetVisibility (callee, LLVMHiddenVisibility);
- g_hash_table_insert (ctx->lmodule->plt_entries, (char*)callee_name, callee);
+ g_hash_table_insert (ctx->module->plt_entries, (char*)callee_name, callee);
}
if (ctx->cfg->compile_aot) {
ji->type = type;
ji->data.target = data;
- g_hash_table_insert (ctx->lmodule->plt_entries_ji, ji, callee);
+ g_hash_table_insert (ctx->module->plt_entries_ji, ji, callee);
}
return callee;
args [1] = LLVMConstInt (LLVMInt32Type (), 0, FALSE);
args [2] = LLVMConstInt (LLVMInt1Type (), TRUE, FALSE);
args [3] = LLVMConstInt (LLVMInt32Type (), ordering, FALSE);
- res = emit_call (ctx, bb, builder_ref, LLVMGetNamedFunction (ctx->module, intrins_name), args, 4);
+ res = emit_call (ctx, bb, builder_ref, LLVMGetNamedFunction (ctx->lmodule, intrins_name), args, 4);
if (addr_type == LLVMPointerType (LLVMDoubleType (), 0))
res = LLVMBuildBitCast (*builder_ref, res, LLVMDoubleType (), "");
args [2] = LLVMConstInt (LLVMInt32Type (), 0, FALSE);
args [3] = LLVMConstInt (LLVMInt1Type (), TRUE, FALSE);
args [4] = LLVMConstInt (LLVMInt32Type (), ordering, FALSE);
- emit_call (ctx, bb, builder_ref, LLVMGetNamedFunction (ctx->module, intrins_name), args, 5);
+ emit_call (ctx, bb, builder_ref, LLVMGetNamedFunction (ctx->lmodule, intrins_name), args, 5);
} else {
mono_llvm_build_store (*builder_ref, value, addr, is_faulting, barrier);
}
return;
}
- callee = ctx->lmodule->throw_corlib_exception;
+ callee = ctx->module->throw_corlib_exception;
if (!callee) {
LLVMTypeRef sig;
const char *icall_name;
if (ctx->cfg->compile_aot) {
callee = get_callee (ctx, sig, MONO_PATCH_INFO_INTERNAL_METHOD, icall_name);
} else {
- callee = LLVMAddFunction (ctx->module, "llvm_throw_corlib_exception_trampoline", sig);
+ callee = LLVMAddFunction (ctx->lmodule, "llvm_throw_corlib_exception_trampoline", sig);
/*
* Differences between the LLVM/non-LLVM throw corlib exception trampoline:
* - On x86, LLVM generated code doesn't push the arguments
* - The trampoline takes the throw address as an arguments, not a pc offset.
*/
- LLVMAddGlobalMapping (ctx->lmodule->ee, callee, resolve_patch (ctx->cfg, MONO_PATCH_INFO_INTERNAL_METHOD, icall_name));
+ LLVMAddGlobalMapping (ctx->module->ee, callee, resolve_patch (ctx->cfg, MONO_PATCH_INFO_INTERNAL_METHOD, icall_name));
mono_memory_barrier ();
- ctx->lmodule->throw_corlib_exception = callee;
+ ctx->module->throw_corlib_exception = callee;
}
}
* Put the global into the 'llvm.used' array to prevent it from being optimized away.
*/
static void
-mark_as_used (MonoLLVMModule *lmodule, LLVMValueRef global)
+mark_as_used (MonoLLVMModule *module, LLVMValueRef global)
{
- if (!lmodule->used)
- lmodule->used = g_ptr_array_sized_new (16);
- g_ptr_array_add (lmodule->used, global);
+ if (!module->used)
+ module->used = g_ptr_array_sized_new (16);
+ g_ptr_array_add (module->used, global);
}
static void
-emit_llvm_used (MonoLLVMModule *lmodule)
+emit_llvm_used (MonoLLVMModule *module)
{
- LLVMModuleRef module = lmodule->module;
+ LLVMModuleRef lmodule = module->lmodule;
LLVMTypeRef used_type;
LLVMValueRef used, *used_elem;
int i;
- if (!lmodule->used)
+ if (!module->used)
return;
- used_type = LLVMArrayType (LLVMPointerType (LLVMInt8Type (), 0), lmodule->used->len);
- used = LLVMAddGlobal (module, used_type, "llvm.used");
- used_elem = g_new0 (LLVMValueRef, lmodule->used->len);
- for (i = 0; i < lmodule->used->len; ++i)
- used_elem [i] = LLVMConstBitCast ((LLVMValueRef)g_ptr_array_index (lmodule->used, i), LLVMPointerType (LLVMInt8Type (), 0));
- LLVMSetInitializer (used, LLVMConstArray (LLVMPointerType (LLVMInt8Type (), 0), used_elem, lmodule->used->len));
+ used_type = LLVMArrayType (LLVMPointerType (LLVMInt8Type (), 0), module->used->len);
+ used = LLVMAddGlobal (lmodule, used_type, "llvm.used");
+ used_elem = g_new0 (LLVMValueRef, module->used->len);
+ for (i = 0; i < module->used->len; ++i)
+ used_elem [i] = LLVMConstBitCast ((LLVMValueRef)g_ptr_array_index (module->used, i), LLVMPointerType (LLVMInt8Type (), 0));
+ LLVMSetInitializer (used, LLVMConstArray (LLVMPointerType (LLVMInt8Type (), 0), used_elem, module->used->len));
LLVMSetLinkage (used, LLVMAppendingLinkage);
LLVMSetSection (used, "llvm.metadata");
}
* Emit a function mapping method indexes to their code
*/
static void
-emit_get_method (MonoLLVMModule *lmodule)
+emit_get_method (MonoLLVMModule *module)
{
- LLVMModuleRef module = lmodule->module;
+ LLVMModuleRef lmodule = module->lmodule;
LLVMValueRef func, switch_ins, m;
LLVMBasicBlockRef entry_bb, fail_bb, bb, code_start_bb, code_end_bb;
LLVMBasicBlockRef *bbs;
* but generating code seems safer.
*/
rtype = LLVMPointerType (LLVMInt8Type (), 0);
- func = LLVMAddFunction (module, lmodule->get_method_symbol, LLVMFunctionType1 (rtype, LLVMInt32Type (), FALSE));
+ func = LLVMAddFunction (lmodule, module->get_method_symbol, LLVMFunctionType1 (rtype, LLVMInt32Type (), FALSE));
LLVMSetLinkage (func, LLVMExternalLinkage);
LLVMSetVisibility (func, LLVMHiddenVisibility);
LLVMAddFunctionAttr (func, LLVMNoUnwindAttribute);
- lmodule->get_method = func;
+ module->get_method = func;
entry_bb = LLVMAppendBasicBlock (func, "ENTRY");
g_free (name);
builder = LLVMCreateBuilder ();
LLVMPositionBuilderAtEnd (builder, code_start_bb);
- LLVMBuildRet (builder, LLVMBuildBitCast (builder, lmodule->code_start, rtype, ""));
+ LLVMBuildRet (builder, LLVMBuildBitCast (builder, module->code_start, rtype, ""));
name = g_strdup_printf ("BB_CODE_END");
code_end_bb = LLVMAppendBasicBlock (func, name);
g_free (name);
builder = LLVMCreateBuilder ();
LLVMPositionBuilderAtEnd (builder, code_end_bb);
- LLVMBuildRet (builder, LLVMBuildBitCast (builder, lmodule->code_end, rtype, ""));
+ LLVMBuildRet (builder, LLVMBuildBitCast (builder, module->code_end, rtype, ""));
- bbs = g_new0 (LLVMBasicBlockRef, lmodule->max_method_idx + 1);
- for (i = 0; i < lmodule->max_method_idx + 1; ++i) {
+ bbs = g_new0 (LLVMBasicBlockRef, module->max_method_idx + 1);
+ for (i = 0; i < module->max_method_idx + 1; ++i) {
name = g_strdup_printf ("BB_%d", i);
bb = LLVMAppendBasicBlock (func, name);
g_free (name);
builder = LLVMCreateBuilder ();
LLVMPositionBuilderAtEnd (builder, bb);
- m = (LLVMValueRef)g_hash_table_lookup (lmodule->idx_to_lmethod, GINT_TO_POINTER (i));
+ m = (LLVMValueRef)g_hash_table_lookup (module->idx_to_lmethod, GINT_TO_POINTER (i));
if (m)
LLVMBuildRet (builder, LLVMBuildBitCast (builder, m, rtype, ""));
else
switch_ins = LLVMBuildSwitch (builder, LLVMGetParam (func, 0), fail_bb, 0);
LLVMAddCase (switch_ins, LLVMConstInt (LLVMInt32Type (), -1, FALSE), code_start_bb);
LLVMAddCase (switch_ins, LLVMConstInt (LLVMInt32Type (), -2, FALSE), code_end_bb);
- for (i = 0; i < lmodule->max_method_idx + 1; ++i) {
+ for (i = 0; i < module->max_method_idx + 1; ++i) {
LLVMAddCase (switch_ins, LLVMConstInt (LLVMInt32Type (), i, FALSE), bbs [i]);
}
- mark_as_used (lmodule, func);
+ mark_as_used (module, func);
}
/*
* Emit a function mapping method indexes to their unbox trampoline
*/
static void
-emit_get_unbox_tramp (MonoLLVMModule *lmodule)
+emit_get_unbox_tramp (MonoLLVMModule *module)
{
- LLVMModuleRef module = lmodule->module;
+ LLVMModuleRef lmodule = module->lmodule;
LLVMValueRef func, switch_ins, m;
LLVMBasicBlockRef entry_bb, fail_bb, bb;
LLVMBasicBlockRef *bbs;
/* Similar to emit_get_method () */
rtype = LLVMPointerType (LLVMInt8Type (), 0);
- func = LLVMAddFunction (module, lmodule->get_unbox_tramp_symbol, LLVMFunctionType1 (rtype, LLVMInt32Type (), FALSE));
+ func = LLVMAddFunction (lmodule, module->get_unbox_tramp_symbol, LLVMFunctionType1 (rtype, LLVMInt32Type (), FALSE));
LLVMSetLinkage (func, LLVMExternalLinkage);
LLVMSetVisibility (func, LLVMHiddenVisibility);
LLVMAddFunctionAttr (func, LLVMNoUnwindAttribute);
- lmodule->get_unbox_tramp = func;
+ module->get_unbox_tramp = func;
entry_bb = LLVMAppendBasicBlock (func, "ENTRY");
- bbs = g_new0 (LLVMBasicBlockRef, lmodule->max_method_idx + 1);
- for (i = 0; i < lmodule->max_method_idx + 1; ++i) {
- m = (LLVMValueRef)g_hash_table_lookup (lmodule->idx_to_unbox_tramp, GINT_TO_POINTER (i));
+ bbs = g_new0 (LLVMBasicBlockRef, module->max_method_idx + 1);
+ for (i = 0; i < module->max_method_idx + 1; ++i) {
+ m = (LLVMValueRef)g_hash_table_lookup (module->idx_to_unbox_tramp, GINT_TO_POINTER (i));
if (!m)
continue;
LLVMPositionBuilderAtEnd (builder, entry_bb);
switch_ins = LLVMBuildSwitch (builder, LLVMGetParam (func, 0), fail_bb, 0);
- for (i = 0; i < lmodule->max_method_idx + 1; ++i) {
- m = (LLVMValueRef)g_hash_table_lookup (lmodule->idx_to_unbox_tramp, GINT_TO_POINTER (i));
+ for (i = 0; i < module->max_method_idx + 1; ++i) {
+ m = (LLVMValueRef)g_hash_table_lookup (module->idx_to_unbox_tramp, GINT_TO_POINTER (i));
if (!m)
continue;
LLVMAddCase (switch_ins, LLVMConstInt (LLVMInt32Type (), i, FALSE), bbs [i]);
}
- mark_as_used (lmodule, func);
+ mark_as_used (module, func);
}
/* Add a function to mark the beginning of LLVM code */
static void
-emit_llvm_code_start (MonoLLVMModule *lmodule)
+emit_llvm_code_start (MonoLLVMModule *module)
{
- LLVMModuleRef module = lmodule->module;
+ LLVMModuleRef lmodule = module->lmodule;
LLVMValueRef func;
LLVMBasicBlockRef entry_bb;
LLVMBuilderRef builder;
- func = LLVMAddFunction (module, "llvm_code_start", LLVMFunctionType (LLVMVoidType (), NULL, 0, FALSE));
+ func = LLVMAddFunction (lmodule, "llvm_code_start", LLVMFunctionType (LLVMVoidType (), NULL, 0, FALSE));
LLVMSetLinkage (func, LLVMInternalLinkage);
LLVMAddFunctionAttr (func, LLVMNoUnwindAttribute);
- lmodule->code_start = func;
+ module->code_start = func;
entry_bb = LLVMAppendBasicBlock (func, "ENTRY");
builder = LLVMCreateBuilder ();
LLVMPositionBuilderAtEnd (builder, entry_bb);
}
static LLVMValueRef
-emit_init_icall_wrapper (MonoLLVMModule *lmodule, const char *name, const char *icall_name, int subtype)
+emit_init_icall_wrapper (MonoLLVMModule *module, const char *name, const char *icall_name, int subtype)
{
- LLVMModuleRef module = lmodule->module;
+ LLVMModuleRef lmodule = module->lmodule;
LLVMValueRef func, indexes [2], got_entry_addr, args [16], callee;
LLVMBasicBlockRef entry_bb;
LLVMBuilderRef builder;
switch (subtype) {
case 0:
- func = LLVMAddFunction (module, name, LLVMFunctionType1 (LLVMVoidType (), LLVMInt32Type (), FALSE));
+ func = LLVMAddFunction (lmodule, name, LLVMFunctionType1 (LLVMVoidType (), LLVMInt32Type (), FALSE));
sig = LLVMFunctionType2 (LLVMVoidType (), IntPtrType (), LLVMInt32Type (), FALSE);
break;
case 1:
- func = LLVMAddFunction (module, name, LLVMFunctionType2 (LLVMVoidType (), LLVMInt32Type (), IntPtrType (), FALSE));
+ func = LLVMAddFunction (lmodule, name, LLVMFunctionType2 (LLVMVoidType (), LLVMInt32Type (), IntPtrType (), FALSE));
sig = LLVMFunctionType3 (LLVMVoidType (), IntPtrType (), LLVMInt32Type (), IntPtrType (), FALSE);
break;
case 2:
- func = LLVMAddFunction (module, name, LLVMFunctionType2 (LLVMVoidType (), LLVMInt32Type (), ObjRefType (), FALSE));
+ func = LLVMAddFunction (lmodule, name, LLVMFunctionType2 (LLVMVoidType (), LLVMInt32Type (), ObjRefType (), FALSE));
sig = LLVMFunctionType3 (LLVMVoidType (), IntPtrType (), LLVMInt32Type (), ObjRefType (), FALSE);
break;
default:
ji->type = MONO_PATCH_INFO_AOT_MODULE;
ji = mono_aot_patch_info_dup (ji);
got_offset = mono_aot_get_got_offset (ji);
- lmodule->max_got_offset = MAX (lmodule->max_got_offset, got_offset);
+ module->max_got_offset = MAX (module->max_got_offset, got_offset);
indexes [0] = LLVMConstInt (LLVMInt32Type (), 0, FALSE);
indexes [1] = LLVMConstInt (LLVMInt32Type (), got_offset, FALSE);
- got_entry_addr = LLVMBuildGEP (builder, lmodule->got_var, indexes, 2, "");
+ got_entry_addr = LLVMBuildGEP (builder, module->got_var, indexes, 2, "");
args [0] = LLVMBuildPtrToInt (builder, LLVMBuildLoad (builder, got_entry_addr, ""), IntPtrType (), "");
args [1] = LLVMGetParam (func, 0);
if (subtype)
ji->data.name = icall_name;
ji = mono_aot_patch_info_dup (ji);
got_offset = mono_aot_get_got_offset (ji);
- lmodule->max_got_offset = MAX (lmodule->max_got_offset, got_offset);
+ module->max_got_offset = MAX (module->max_got_offset, got_offset);
indexes [0] = LLVMConstInt (LLVMInt32Type (), 0, FALSE);
indexes [1] = LLVMConstInt (LLVMInt32Type (), got_offset, FALSE);
- got_entry_addr = LLVMBuildGEP (builder, lmodule->got_var, indexes, 2, "");
+ got_entry_addr = LLVMBuildGEP (builder, module->got_var, indexes, 2, "");
callee = LLVMBuildLoad (builder, got_entry_addr, "");
callee = LLVMBuildBitCast (builder, callee, LLVMPointerType (sig, 0), "");
LLVMBuildCall (builder, callee, args, LLVMCountParamTypes (sig), "");
// Set the inited flag
indexes [0] = LLVMConstInt (LLVMInt32Type (), 0, FALSE);
indexes [1] = LLVMGetParam (func, 0);
- LLVMBuildStore (builder, LLVMConstInt (LLVMInt8Type (), 1, FALSE), LLVMBuildGEP (builder, lmodule->inited_var, indexes, 2, ""));
+ LLVMBuildStore (builder, LLVMConstInt (LLVMInt8Type (), 1, FALSE), LLVMBuildGEP (builder, module->inited_var, indexes, 2, ""));
LLVMBuildRetVoid (builder);
* PreserveAll calling convention.
*/
static void
-emit_init_icall_wrappers (MonoLLVMModule *lmodule)
+emit_init_icall_wrappers (MonoLLVMModule *module)
{
- lmodule->init_method = emit_init_icall_wrapper (lmodule, "init_method", "mono_aot_init_llvm_method", 0);
- lmodule->init_method_gshared_rgctx = emit_init_icall_wrapper (lmodule, "init_method_gshared_rgctx", "mono_aot_init_gshared_method_rgctx", 1);
- lmodule->init_method_gshared_this = emit_init_icall_wrapper (lmodule, "init_method_gshared_this", "mono_aot_init_gshared_method_this", 2);
+ module->init_method = emit_init_icall_wrapper (module, "init_method", "mono_aot_init_llvm_method", 0);
+ module->init_method_gshared_rgctx = emit_init_icall_wrapper (module, "init_method_gshared_rgctx", "mono_aot_init_gshared_method_rgctx", 1);
+ module->init_method_gshared_this = emit_init_icall_wrapper (module, "init_method_gshared_this", "mono_aot_init_gshared_method_this", 2);
}
static void
-emit_llvm_code_end (MonoLLVMModule *lmodule)
+emit_llvm_code_end (MonoLLVMModule *module)
{
- LLVMModuleRef module = lmodule->module;
+ LLVMModuleRef lmodule = module->lmodule;
LLVMValueRef func;
LLVMBasicBlockRef entry_bb;
LLVMBuilderRef builder;
- func = LLVMAddFunction (module, "llvm_code_end", LLVMFunctionType (LLVMVoidType (), NULL, 0, FALSE));
+ func = LLVMAddFunction (lmodule, "llvm_code_end", LLVMFunctionType (LLVMVoidType (), NULL, 0, FALSE));
LLVMSetLinkage (func, LLVMInternalLinkage);
LLVMAddFunctionAttr (func, LLVMNoUnwindAttribute);
- lmodule->code_end = func;
+ module->code_end = func;
entry_bb = LLVMAppendBasicBlock (func, "ENTRY");
builder = LLVMCreateBuilder ();
LLVMPositionBuilderAtEnd (builder, entry_bb);
LLVMBuilderRef builder = ctx->builder;
MonoCompile *cfg = ctx->cfg;
- ctx->lmodule->max_inited_idx = MAX (ctx->lmodule->max_inited_idx, cfg->method_index);
- ctx->lmodule->max_method_idx = MAX (ctx->lmodule->max_method_idx, cfg->method_index);
+ ctx->module->max_inited_idx = MAX (ctx->module->max_inited_idx, cfg->method_index);
+ ctx->module->max_method_idx = MAX (ctx->module->max_method_idx, cfg->method_index);
indexes [0] = LLVMConstInt (LLVMInt32Type (), 0, FALSE);
indexes [1] = LLVMConstInt (LLVMInt32Type (), cfg->method_index, FALSE);
- inited_var = LLVMBuildLoad (builder, LLVMBuildGEP (builder, ctx->lmodule->inited_var, indexes, 2, ""), "");
+ inited_var = LLVMBuildLoad (builder, LLVMBuildGEP (builder, ctx->module->inited_var, indexes, 2, ""), "");
args [0] = inited_var;
args [1] = LLVMConstInt (LLVMInt8Type (), 1, FALSE);
- inited_var = LLVMBuildCall (ctx->builder, LLVMGetNamedFunction (ctx->module, "llvm.expect.i8"), args, 2, "");
+ inited_var = LLVMBuildCall (ctx->builder, LLVMGetNamedFunction (ctx->lmodule, "llvm.expect.i8"), args, 2, "");
cmp = LLVMBuildICmp (builder, LLVMIntEQ, inited_var, LLVMConstInt (LLVMTypeOf (inited_var), 0, FALSE), "");
if (ctx->rgctx_arg) {
args [0] = LLVMConstInt (LLVMInt32Type (), cfg->method_index, 0);
args [1] = convert (ctx, ctx->rgctx_arg, IntPtrType ());
- callee = ctx->lmodule->init_method_gshared_rgctx;
+ callee = ctx->module->init_method_gshared_rgctx;
call = LLVMBuildCall (builder, callee, args, 2, "");
} else if (cfg->gshared) {
args [0] = LLVMConstInt (LLVMInt32Type (), cfg->method_index, 0);
args [1] = convert (ctx, ctx->this_arg, ObjRefType ());
- callee = ctx->lmodule->init_method_gshared_this;
+ callee = ctx->module->init_method_gshared_this;
call = LLVMBuildCall (builder, callee, args, 2, "");
} else {
args [0] = LLVMConstInt (LLVMInt32Type (), cfg->method_index, 0);
- callee = ctx->lmodule->init_method;
+ callee = ctx->module->init_method;
call = LLVMBuildCall (builder, callee, args, 1, "");
}
int i, nargs;
tramp_name = g_strdup_printf ("ut_%s", method_name);
- tramp = LLVMAddFunction (ctx->lmodule->module, tramp_name, method_type);
+ tramp = LLVMAddFunction (ctx->module->lmodule, tramp_name, method_type);
LLVMSetLinkage (tramp, LLVMInternalLinkage);
LLVMAddFunctionAttr (tramp, LLVMNoUnwindAttribute);
if (!ctx->llvm_only && ctx->rgctx_arg_pindex != -1)
else
LLVMBuildRet (builder, call);
- g_hash_table_insert (ctx->lmodule->idx_to_unbox_tramp, GINT_TO_POINTER (method_index), tramp);
+ g_hash_table_insert (ctx->module->idx_to_unbox_tramp, GINT_TO_POINTER (method_index), tramp);
}
/*
process_call (EmitContext *ctx, MonoBasicBlock *bb, LLVMBuilderRef *builder_ref, MonoInst *ins)
{
MonoCompile *cfg = ctx->cfg;
- LLVMModuleRef module = ctx->module;
+ LLVMModuleRef lmodule = ctx->lmodule;
LLVMValueRef *values = ctx->values;
LLVMValueRef *addresses = ctx->addresses;
MonoCallInst *call = (MonoCallInst*)ins;
if (!callee)
LLVM_FAILURE (ctx, "can't encode patch");
- if (cfg->llvm_only && call->method->klass->image->assembly == ctx->lmodule->assembly) {
+ if (cfg->llvm_only && call->method->klass->image->assembly == ctx->module->assembly) {
/*
* Collect instructions representing the callee into a hash so they can be replaced
* by the llvm method for the callee if the callee turns out to be direct
g_hash_table_insert (ctx->method_to_callers, call->method, l);
}
} else {
- callee = LLVMAddFunction (module, "", llvm_sig);
+ callee = LLVMAddFunction (lmodule, "", llvm_sig);
target =
mono_create_jit_trampoline_in_domain (mono_domain_get (),
call->method);
- LLVMAddGlobalMapping (ctx->lmodule->ee, callee, target);
+ LLVMAddGlobalMapping (ctx->module->ee, callee, target);
}
}
if (!callee)
LLVM_FAILURE (ctx, "can't encode patch");
} else {
- callee = LLVMAddFunction (module, "", llvm_sig);
+ callee = LLVMAddFunction (lmodule, "", llvm_sig);
target = (gpointer)mono_icall_get_wrapper (info);
- LLVMAddGlobalMapping (ctx->lmodule->ee, callee, target);
+ LLVMAddGlobalMapping (ctx->module->ee, callee, target);
}
} else {
if (cfg->compile_aot) {
if (!callee)
LLVM_FAILURE (ctx, "aot");
} else {
- callee = LLVMAddFunction (module, "", llvm_sig);
+ callee = LLVMAddFunction (lmodule, "", llvm_sig);
target = NULL;
if (cfg->abs_patches) {
MonoJumpInfo *abs_ji = (MonoJumpInfo*)g_hash_table_lookup (cfg->abs_patches, call->fptr);
LLVM_FAILURE (ctx, "trampoline with own cconv");
#endif
target = mono_resolve_patch_target (cfg->method, cfg->domain, NULL, abs_ji, FALSE);
- LLVMAddGlobalMapping (ctx->lmodule->ee, callee, target);
+ LLVMAddGlobalMapping (ctx->module->ee, callee, target);
}
}
if (!target)
- LLVMAddGlobalMapping (ctx->lmodule->ee, callee, (gpointer)call->fptr);
+ LLVMAddGlobalMapping (ctx->module->ee, callee, (gpointer)call->fptr);
}
}
}
*/
#ifdef TARGET_ARM
if (!ctx->imt_rgctx_loc)
- ctx->imt_rgctx_loc = build_alloca_llvm_type (ctx, ctx->lmodule->ptr_type, sizeof (gpointer));
- LLVMBuildStore (builder, convert (ctx, ctx->values [call->rgctx_arg_reg], ctx->lmodule->ptr_type), ctx->imt_rgctx_loc);
+ ctx->imt_rgctx_loc = build_alloca_llvm_type (ctx, ctx->module->ptr_type, sizeof (gpointer));
+ LLVMBuildStore (builder, convert (ctx, ctx->values [call->rgctx_arg_reg], ctx->module->ptr_type), ctx->imt_rgctx_loc);
args [sinfo.rgctx_arg_pindex] = mono_llvm_build_load (builder, ctx->imt_rgctx_loc, "", TRUE, LLVM_BARRIER_NONE);
#else
- args [cinfo->rgctx_arg_pindex] = convert (ctx, values [call->rgctx_arg_reg], ctx->lmodule->ptr_type);
+ args [cinfo->rgctx_arg_pindex] = convert (ctx, values [call->rgctx_arg_reg], ctx->module->ptr_type);
#endif
}
if (call->imt_arg_reg) {
g_assert (cinfo->imt_arg_pindex < nargs);
#ifdef TARGET_ARM
if (!ctx->imt_rgctx_loc)
- ctx->imt_rgctx_loc = build_alloca_llvm_type (ctx, ctx->lmodule->ptr_type, sizeof (gpointer));
- LLVMBuildStore (builder, convert (ctx, ctx->values [call->imt_arg_reg], ctx->lmodule->ptr_type), ctx->imt_rgctx_loc);
+ ctx->imt_rgctx_loc = build_alloca_llvm_type (ctx, ctx->module->ptr_type, sizeof (gpointer));
+ LLVMBuildStore (builder, convert (ctx, ctx->values [call->imt_arg_reg], ctx->module->ptr_type), ctx->imt_rgctx_loc);
args [cinfo->imt_arg_pindex] = mono_llvm_build_load (builder, ctx->imt_rgctx_loc, "", TRUE, LLVM_BARRIER_NONE);
#else
- args [cinfo->imt_arg_pindex] = convert (ctx, values [call->imt_arg_reg], ctx->lmodule->ptr_type);
+ args [cinfo->imt_arg_pindex] = convert (ctx, values [call->imt_arg_reg], ctx->module->ptr_type);
#endif
}
if (vretaddr) {
emit_llvmonly_throw (EmitContext *ctx, MonoBasicBlock *bb, gboolean rethrow, LLVMValueRef exc)
{
const char *icall_name = rethrow ? "mono_llvm_rethrow_exception" : "mono_llvm_throw_exception";
- LLVMValueRef callee = rethrow ? ctx->lmodule->rethrow : ctx->lmodule->throw_icall;
+ LLVMValueRef callee = rethrow ? ctx->module->rethrow : ctx->module->throw_icall;
LLVMTypeRef exc_type = type_to_llvm_type (ctx, &mono_get_exception_class ()->byval_arg);
if (ctx->cfg->compile_aot) {
callee = get_callee (ctx, fun_sig, MONO_PATCH_INFO_INTERNAL_METHOD, icall_name);
} else {
- callee = LLVMAddFunction (ctx->module, icall_name, fun_sig);
- LLVMAddGlobalMapping (ctx->lmodule->ee, callee, resolve_patch (ctx->cfg, MONO_PATCH_INFO_INTERNAL_METHOD, icall_name));
+ callee = LLVMAddFunction (ctx->lmodule, icall_name, fun_sig);
+ LLVMAddGlobalMapping (ctx->module->ee, callee, resolve_patch (ctx->cfg, MONO_PATCH_INFO_INTERNAL_METHOD, icall_name));
mono_memory_barrier ();
if (rethrow)
- ctx->lmodule->rethrow = callee;
+ ctx->module->rethrow = callee;
else
- ctx->lmodule->throw_icall = callee;
+ ctx->module->throw_icall = callee;
}
}
LLVMValueRef callee, arg;
const char *icall_name;
- callee = rethrow ? ctx->lmodule->rethrow : ctx->lmodule->throw_icall;
+ callee = rethrow ? ctx->module->rethrow : ctx->module->throw_icall;
icall_name = rethrow ? "mono_arch_rethrow_exception" : "mono_arch_throw_exception";
if (!callee) {
if (ctx->cfg->compile_aot) {
callee = get_callee (ctx, sig_to_llvm_sig (ctx, throw_sig), MONO_PATCH_INFO_INTERNAL_METHOD, icall_name);
} else {
- callee = LLVMAddFunction (ctx->module, icall_name, sig_to_llvm_sig (ctx, throw_sig));
+ callee = LLVMAddFunction (ctx->lmodule, icall_name, sig_to_llvm_sig (ctx, throw_sig));
#ifdef TARGET_X86
/*
* LLVM doesn't push the exception argument, so we need a different
* trampoline.
*/
- LLVMAddGlobalMapping (ctx->lmodule->ee, callee, resolve_patch (ctx->cfg, MONO_PATCH_INFO_INTERNAL_METHOD, rethrow ? "llvm_rethrow_exception_trampoline" : "llvm_throw_exception_trampoline"));
+ LLVMAddGlobalMapping (ctx->module->ee, callee, resolve_patch (ctx->cfg, MONO_PATCH_INFO_INTERNAL_METHOD, rethrow ? "llvm_rethrow_exception_trampoline" : "llvm_throw_exception_trampoline"));
#else
- LLVMAddGlobalMapping (ctx->lmodule->ee, callee, resolve_patch (ctx->cfg, MONO_PATCH_INFO_INTERNAL_METHOD, icall_name));
+ LLVMAddGlobalMapping (ctx->module->ee, callee, resolve_patch (ctx->cfg, MONO_PATCH_INFO_INTERNAL_METHOD, icall_name));
#endif
}
mono_memory_barrier ();
if (rethrow)
- ctx->lmodule->rethrow = callee;
+ ctx->module->rethrow = callee;
else
- ctx->lmodule->throw_icall = callee;
+ ctx->module->throw_icall = callee;
}
arg = convert (ctx, exc, type_to_llvm_type (ctx, &mono_get_object_class ()->byval_arg));
emit_call (ctx, bb, &ctx->builder, callee, &arg, 1);
emit_resume_eh (EmitContext *ctx, MonoBasicBlock *bb)
{
const char *icall_name = "mono_llvm_resume_exception";
- LLVMValueRef callee = ctx->lmodule->resume_eh;
+ LLVMValueRef callee = ctx->module->resume_eh;
LLVMTypeRef fun_sig = LLVMFunctionType0 (LLVMVoidType (), FALSE);
if (ctx->cfg->compile_aot) {
callee = get_callee (ctx, fun_sig, MONO_PATCH_INFO_INTERNAL_METHOD, icall_name);
} else {
- callee = LLVMAddFunction (ctx->module, icall_name, fun_sig);
- LLVMAddGlobalMapping (ctx->lmodule->ee, callee, resolve_patch (ctx->cfg, MONO_PATCH_INFO_INTERNAL_METHOD, icall_name));
+ callee = LLVMAddFunction (ctx->lmodule, icall_name, fun_sig);
+ LLVMAddGlobalMapping (ctx->module->ee, callee, resolve_patch (ctx->cfg, MONO_PATCH_INFO_INTERNAL_METHOD, icall_name));
mono_memory_barrier ();
- ctx->lmodule->resume_eh = callee;
+ ctx->module->resume_eh = callee;
}
}
callee = get_callee (ctx, call_sig, MONO_PATCH_INFO_INTERNAL_METHOD, icall_name);
} else {
// FIXME: This is broken.
- callee = LLVMAddFunction (ctx->module, icall_name, call_sig);
+ callee = LLVMAddFunction (ctx->lmodule, icall_name, call_sig);
}
}
callee = get_callee (ctx, call_sig, MONO_PATCH_INFO_INTERNAL_METHOD, icall_name);
} else {
// FIXME: This is broken.
- callee = LLVMAddFunction (ctx->module, icall_name, call_sig);
+ callee = LLVMAddFunction (ctx->lmodule, icall_name, call_sig);
}
}
args [2] = LLVMConstInt (LLVMInt32Type (), region_end, 0);
LLVMTypeRef match_sig = LLVMFunctionType3 (LLVMInt32Type (), IntPtrType (), LLVMInt32Type (), LLVMInt32Type (), FALSE);
- LLVMValueRef callee = ctx->lmodule->match_exc;
+ LLVMValueRef callee = ctx->module->match_exc;
if (!callee) {
if (ctx->cfg->compile_aot) {
// get_callee expects ctx->builder to be the emitting builder
callee = get_callee (ctx, match_sig, MONO_PATCH_INFO_INTERNAL_METHOD, icall_name);
} else {
- callee = ctx->lmodule->match_exc = LLVMAddFunction (ctx->module, icall_name, match_sig);
- LLVMAddGlobalMapping (ctx->lmodule->ee, ctx->lmodule->match_exc, resolve_patch (ctx->cfg, MONO_PATCH_INFO_INTERNAL_METHOD, icall_name));
- ctx->lmodule->match_exc = callee;
+ callee = ctx->module->match_exc = LLVMAddFunction (ctx->lmodule, icall_name, match_sig);
+ LLVMAddGlobalMapping (ctx->module->ee, ctx->module->match_exc, resolve_patch (ctx->cfg, MONO_PATCH_INFO_INTERNAL_METHOD, icall_name));
+ ctx->module->match_exc = callee;
mono_memory_barrier ();
}
}
if (!use_debug_personality) {
if (ctx->cfg->compile_aot) {
- personality = LLVMGetNamedFunction (ctx->module, default_personality_name);
+ personality = LLVMGetNamedFunction (ctx->lmodule, default_personality_name);
} else if (InterlockedCompareExchange (&mapping_inited, 1, 0) == 0) {
- personality = LLVMAddFunction (ctx->module, default_personality_name, personality_type);
- LLVMAddGlobalMapping (ctx->lmodule->ee, personality, personality);
+ personality = LLVMAddFunction (ctx->lmodule, default_personality_name, personality_type);
+ LLVMAddGlobalMapping (ctx->module->ee, personality, personality);
}
} else {
if (ctx->cfg->compile_aot) {
personality = get_callee (ctx, personality_type, MONO_PATCH_INFO_INTERNAL_METHOD, default_personality_name);
} else {
- personality = LLVMAddFunction (ctx->module, default_personality_name, personality_type);
- LLVMAddGlobalMapping (ctx->lmodule->ee, personality, resolve_patch (ctx->cfg, MONO_PATCH_INFO_INTERNAL_METHOD, default_personality_name));
+ personality = LLVMAddFunction (ctx->lmodule, default_personality_name, personality_type);
+ LLVMAddGlobalMapping (ctx->module->ee, personality, resolve_patch (ctx->cfg, MONO_PATCH_INFO_INTERNAL_METHOD, default_personality_name));
mono_memory_barrier ();
}
}
LLVMValueRef landing_pad = LLVMBuildLandingPad (lpadBuilder, default_cpp_lpad_exc_signature (), personality, 0, "");
g_assert (landing_pad);
- LLVMValueRef cast = LLVMBuildBitCast (lpadBuilder, ctx->lmodule->sentinel_exception, LLVMPointerType (LLVMInt8Type (), 0), "int8TypeInfo");
+ LLVMValueRef cast = LLVMBuildBitCast (lpadBuilder, ctx->module->sentinel_exception, LLVMPointerType (LLVMInt8Type (), 0), "int8TypeInfo");
LLVMAddClause (landing_pad, cast);
LLVMBasicBlockRef resume_bb = gen_bb (ctx, "RESUME_BB");
{
MonoCompile *cfg = ctx->cfg;
LLVMValueRef *values = ctx->values;
- LLVMModuleRef module = ctx->module;
+ LLVMModuleRef lmodule = ctx->lmodule;
BBInfo *bblocks = ctx->bblocks;
LLVMTypeRef i8ptr;
LLVMValueRef personality;
if (cfg->compile_aot) {
/* Use a dummy personality function */
- personality = LLVMGetNamedFunction (module, "mono_personality");
+ personality = LLVMGetNamedFunction (lmodule, "mono_personality");
g_assert (personality);
} else {
- personality = LLVMGetNamedFunction (module, "mono_personality");
+ personality = LLVMGetNamedFunction (lmodule, "mono_personality");
if (InterlockedCompareExchange (&mapping_inited, 1, 0) == 0)
- LLVMAddGlobalMapping (ctx->lmodule->ee, personality, mono_personality);
+ LLVMAddGlobalMapping (ctx->module->ee, personality, mono_personality);
}
i8ptr = LLVMPointerType (LLVMInt8Type (), 0);
if (cfg->compile_aot) {
/* decode_eh_frame () in aot-runtime.c will decode this */
- type_info = LLVMAddGlobal (module, LLVMInt32Type (), ti_name);
+ type_info = LLVMAddGlobal (lmodule, LLVMInt32Type (), ti_name);
LLVMSetInitializer (type_info, LLVMConstInt (LLVMInt32Type (), clause_index, FALSE));
/*
ti = mono_mempool_alloc (cfg->mempool, sizeof (gint32));
*(gint32*)ti = clause_index;
- type_info = LLVMAddGlobal (module, i8ptr, ti_name);
+ type_info = LLVMAddGlobal (lmodule, i8ptr, ti_name);
- LLVMAddGlobalMapping (ctx->lmodule->ee, type_info, ti);
+ LLVMAddGlobalMapping (ctx->module->ee, type_info, ti);
}
{
LLVMValueRef *values = ctx->values;
LLVMValueRef *addresses = ctx->addresses;
LLVMCallInfo *linfo = ctx->linfo;
- LLVMModuleRef module = ctx->module;
+ LLVMModuleRef lmodule = ctx->lmodule;
BBInfo *bblocks = ctx->bblocks;
MonoInst *ins;
LLVMBasicBlockRef cbb;
args [2] = LLVMConstInt (LLVMInt32Type (), size, FALSE);
args [3] = LLVMConstInt (LLVMInt32Type (), MONO_ARCH_FRAME_ALIGNMENT, FALSE);
args [4] = LLVMConstInt (LLVMInt1Type (), 0, FALSE);
- LLVMBuildCall (builder, LLVMGetNamedFunction (module, memset_func_name), args, memset_param_count, "");
+ LLVMBuildCall (builder, LLVMGetNamedFunction (lmodule, memset_func_name), args, memset_param_count, "");
}
values [ins->dreg] = v;
args [2] = size;
args [3] = LLVMConstInt (LLVMInt32Type (), MONO_ARCH_FRAME_ALIGNMENT, FALSE);
args [4] = LLVMConstInt (LLVMInt1Type (), 0, FALSE);
- LLVMBuildCall (builder, LLVMGetNamedFunction (module, memset_func_name), args, memset_param_count, "");
+ LLVMBuildCall (builder, LLVMGetNamedFunction (lmodule, memset_func_name), args, memset_param_count, "");
}
values [ins->dreg] = v;
break;
//mono_add_patch_info (cfg, 0, (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
got_offset = mono_aot_get_got_offset (cfg->patch_info);
- ctx->lmodule->max_got_offset = MAX (ctx->lmodule->max_got_offset, got_offset);
+ ctx->module->max_got_offset = MAX (ctx->module->max_got_offset, got_offset);
if (!mono_aot_is_shared_got_offset (got_offset)) {
//mono_print_ji (ji);
//printf ("\n");
indexes [0] = LLVMConstInt (LLVMInt32Type (), 0, FALSE);
indexes [1] = LLVMConstInt (LLVMInt32Type (), (gssize)got_offset, FALSE);
- got_entry_addr = LLVMBuildGEP (builder, ctx->lmodule->got_var, indexes, 2, "");
+ got_entry_addr = LLVMBuildGEP (builder, ctx->module->got_var, indexes, 2, "");
values [ins->dreg] = LLVMBuildLoad (builder, got_entry_addr, dname);
set_invariant_load_flag (values [ins->dreg]);
LLVMValueRef args [1];
args [0] = convert (ctx, lhs, LLVMDoubleType ());
- values [ins->dreg] = LLVMBuildCall (builder, LLVMGetNamedFunction (module, "llvm.sin.f64"), args, 1, dname);
+ values [ins->dreg] = LLVMBuildCall (builder, LLVMGetNamedFunction (lmodule, "llvm.sin.f64"), args, 1, dname);
break;
}
case OP_COS: {
LLVMValueRef args [1];
args [0] = convert (ctx, lhs, LLVMDoubleType ());
- values [ins->dreg] = LLVMBuildCall (builder, LLVMGetNamedFunction (module, "llvm.cos.f64"), args, 1, dname);
+ values [ins->dreg] = LLVMBuildCall (builder, LLVMGetNamedFunction (lmodule, "llvm.cos.f64"), args, 1, dname);
break;
}
case OP_SQRT: {
LLVM_FAILURE (ctx, "sqrt");
#endif
args [0] = convert (ctx, lhs, LLVMDoubleType ());
- values [ins->dreg] = LLVMBuildCall (builder, LLVMGetNamedFunction (module, "llvm.sqrt.f64"), args, 1, dname);
+ values [ins->dreg] = LLVMBuildCall (builder, LLVMGetNamedFunction (lmodule, "llvm.sqrt.f64"), args, 1, dname);
break;
}
case OP_ABS: {
LLVMValueRef args [1];
args [0] = convert (ctx, lhs, LLVMDoubleType ());
- values [ins->dreg] = LLVMBuildCall (builder, LLVMGetNamedFunction (module, "fabs"), args, 1, dname);
+ values [ins->dreg] = LLVMBuildCall (builder, LLVMGetNamedFunction (lmodule, "fabs"), args, 1, dname);
break;
}
}
case OP_RELAXED_NOP: {
#if defined(TARGET_AMD64) || defined(TARGET_X86)
- emit_call (ctx, bb, &builder, LLVMGetNamedFunction (ctx->module, "llvm.x86.sse2.pause"), NULL, 0);
+ emit_call (ctx, bb, &builder, LLVMGetNamedFunction (ctx->lmodule, "llvm.x86.sse2.pause"), NULL, 0);
break;
#else
break;
args [0] = convert (ctx, lhs, op_to_llvm_type (ins->opcode));
args [1] = convert (ctx, rhs, op_to_llvm_type (ins->opcode));
- func = LLVMGetNamedFunction (module, ovf_op_to_intrins (ins->opcode));
+ func = LLVMGetNamedFunction (lmodule, ovf_op_to_intrins (ins->opcode));
g_assert (func);
val = LLVMBuildCall (builder, func, args, 2, "");
values [ins->dreg] = LLVMBuildExtractValue (builder, val, 0, dname);
// FIXME: Alignment
args [3] = LLVMConstInt (LLVMInt32Type (), 0, FALSE);
args [4] = LLVMConstInt (LLVMInt1Type (), 0, FALSE);
- LLVMBuildCall (builder, LLVMGetNamedFunction (module, memset_func_name), args, memset_param_count, "");
+ LLVMBuildCall (builder, LLVMGetNamedFunction (lmodule, memset_func_name), args, memset_param_count, "");
break;
}
case OP_DUMMY_VZERO:
// FIXME: Alignment
args [3] = LLVMConstInt (LLVMInt32Type (), 0, FALSE);
args [4] = LLVMConstInt (LLVMInt1Type (), 0, FALSE);
- LLVMBuildCall (builder, LLVMGetNamedFunction (module, memcpy_func_name), args, memcpy_param_count, "");
+ LLVMBuildCall (builder, LLVMGetNamedFunction (lmodule, memcpy_func_name), args, memcpy_param_count, "");
break;
}
case OP_LLVM_OUTARG_VT:
args [0] = lhs;
args [1] = rhs;
- values [ins->dreg] = LLVMBuildCall (builder, LLVMGetNamedFunction (module, simd_op_to_intrins (ins->opcode)), args, 2, dname);
+ values [ins->dreg] = LLVMBuildCall (builder, LLVMGetNamedFunction (lmodule, simd_op_to_intrins (ins->opcode)), args, 2, dname);
break;
}
case OP_PCMPEQB:
v = convert (ctx, values [ins->sreg1], simd_op_to_llvm_type (ins->opcode));
- values [ins->dreg] = LLVMBuildCall (builder, LLVMGetNamedFunction (module, simd_op_to_intrins (ins->opcode)), &v, 1, dname);
+ values [ins->dreg] = LLVMBuildCall (builder, LLVMGetNamedFunction (lmodule, simd_op_to_intrins (ins->opcode)), &v, 1, dname);
break;
}
args [1] = rhs;
args [2] = LLVMConstInt (LLVMInt8Type (), ins->inst_c0, FALSE);
- values [ins->dreg] = LLVMBuildCall (builder, LLVMGetNamedFunction (module, simd_op_to_intrins (ins->opcode)), args, 3, dname);
+ values [ins->dreg] = LLVMBuildCall (builder, LLVMGetNamedFunction (lmodule, simd_op_to_intrins (ins->opcode)), args, 3, dname);
break;
}
args [0] = lhs;
args [1] = LLVMConstInt (LLVMInt32Type (), ins->inst_imm, FALSE);
- values [ins->dreg] = LLVMBuildCall (builder, LLVMGetNamedFunction (module, simd_op_to_intrins (ins->opcode)), args, 2, dname);
+ values [ins->dreg] = LLVMBuildCall (builder, LLVMGetNamedFunction (lmodule, simd_op_to_intrins (ins->opcode)), args, 2, dname);
break;
}
args [0] = lhs;
args [1] = values [ins->sreg2];
- values [ins->dreg] = LLVMBuildCall (builder, LLVMGetNamedFunction (module, simd_op_to_intrins (ins->opcode)), args, 2, dname);
+ values [ins->dreg] = LLVMBuildCall (builder, LLVMGetNamedFunction (lmodule, simd_op_to_intrins (ins->opcode)), args, 2, dname);
break;
}
if (ctx->cfg->compile_aot) {
callee = get_callee (ctx, LLVMFunctionType (LLVMVoidType (), NULL, 0, FALSE), MONO_PATCH_INFO_INTERNAL_METHOD, "llvm_resume_unwind_trampoline");
} else {
- callee = LLVMGetNamedFunction (module, "llvm_resume_unwind_trampoline");
+ callee = LLVMGetNamedFunction (lmodule, "llvm_resume_unwind_trampoline");
}
LLVMBuildCall (builder, callee, NULL, 0, "");
LLVMBuildUnreachable (builder);
GPtrArray *phi_values;
LLVMCallInfo *linfo;
GSList *l;
- LLVMModuleRef module;
+ LLVMModuleRef lmodule;
BBInfo *bblocks;
GPtrArray *bblock_list;
MonoMethodHeader *header;
ctx->method_to_callers = g_hash_table_new (NULL, NULL);
if (cfg->compile_aot) {
- ctx->lmodule = &aot_module;
+ ctx->module = &aot_module;
method_name = mono_aot_get_method_name (cfg);
cfg->llvm_method_name = g_strdup (method_name);
} else {
init_jit_module (cfg->domain);
- ctx->lmodule = (MonoLLVMModule*)domain_jit_info (cfg->domain)->llvm_module;
+ ctx->module = (MonoLLVMModule*)domain_jit_info (cfg->domain)->llvm_module;
method_name = mono_method_full_name (cfg->method, TRUE);
}
- module = ctx->module = ctx->lmodule->module;
- ctx->llvm_only = ctx->lmodule->llvm_only;
+ lmodule = ctx->lmodule = ctx->module->lmodule;
+ ctx->llvm_only = ctx->module->llvm_only;
if (cfg->gsharedvt)
LLVM_FAILURE (ctx, "gsharedvt");
*/
ctx->pindexes = linfo->pindexes;
- method = LLVMAddFunction (module, method_name, method_type);
+ method = LLVMAddFunction (lmodule, method_name, method_type);
ctx->lmethod = method;
if (!cfg->llvm_only)
if (cfg->compile_aot) {
LLVMSetLinkage (method, LLVMInternalLinkage);
- if (ctx->lmodule->external_symbols) {
+ if (ctx->module->external_symbols) {
LLVMSetLinkage (method, LLVMExternalLinkage);
LLVMSetVisibility (method, LLVMHiddenVisibility);
}
}
g_free (names);
- if (ctx->lmodule->emit_dwarf && cfg->compile_aot && mono_debug_enabled ()) {
+ if (ctx->module->emit_dwarf && cfg->compile_aot && mono_debug_enabled ()) {
ctx->minfo = mono_debug_lookup_method (cfg->method);
ctx->dbg_md = emit_dbg_subprogram (ctx, cfg, method, method_name);
}
GSList *callers, *l, *l2;
/*
- * Add the contents of ctx->method_to_callers to lmodule->method_to_callers.
+ * Add the contents of ctx->method_to_callers to module->method_to_callers.
* We can't do this earlier, as it contains llvm instructions which can be
* freed if compilation fails.
* FIXME: Get rid of this when all methods can be llvm compiled.
g_hash_table_iter_init (&iter, ctx->method_to_callers);
while (g_hash_table_iter_next (&iter, (void**)&method, (void**)&callers)) {
for (l = callers; l; l = l->next) {
- l2 = g_hash_table_lookup (ctx->lmodule->method_to_callers, method);
+ l2 = g_hash_table_lookup (ctx->module->method_to_callers, method);
l2 = g_slist_prepend (l2, l->data);
- g_hash_table_insert (ctx->lmodule->method_to_callers, method, l2);
+ g_hash_table_insert (ctx->module->method_to_callers, method, l2);
}
}
}
mono_llvm_dump_value (method);
if (cfg->compile_aot && !cfg->llvm_only)
- mark_as_used (ctx->lmodule, method);
+ mark_as_used (ctx->module, method);
if (cfg->compile_aot) {
LLVMValueRef md_args [16];
md_args [0] = LLVMMDString (method_name, strlen (method_name));
md_args [1] = LLVMConstInt (LLVMInt32Type (), method_index, FALSE);
md_node = LLVMMDNode (md_args, 2);
- LLVMAddNamedMetadataOperand (module, "mono.function_indexes", md_node);
+ LLVMAddNamedMetadataOperand (lmodule, "mono.function_indexes", md_node);
//LLVMSetMetadata (method, md_kind, LLVMMDNode (&md_arg, 1));
}
LLVMVerifyFunction(method, 0);
} else {
LLVMVerifyFunction(method, 0);
- mono_llvm_optimize_method (ctx->lmodule->mono_ee, method);
+ mono_llvm_optimize_method (ctx->module->mono_ee, method);
if (cfg->verbose_level > 1)
mono_llvm_dump_value (method);
- cfg->native_code = LLVMGetPointerToGlobal (ctx->lmodule->ee, method);
+ cfg->native_code = LLVMGetPointerToGlobal (ctx->module->ee, method);
/* Set by emit_cb */
g_assert (cfg->code_len);
/* FIXME: Free the LLVM IL for the function */
}
- if (ctx->lmodule->method_to_lmethod)
- g_hash_table_insert (ctx->lmodule->method_to_lmethod, cfg->method, method);
- if (ctx->lmodule->idx_to_lmethod)
- g_hash_table_insert (ctx->lmodule->idx_to_lmethod, GINT_TO_POINTER (cfg->method_index), method);
+ if (ctx->module->method_to_lmethod)
+ g_hash_table_insert (ctx->module->method_to_lmethod, cfg->method, method);
+ if (ctx->module->idx_to_lmethod)
+ g_hash_table_insert (ctx->module->idx_to_lmethod, GINT_TO_POINTER (cfg->method_index), method);
if (ctx->llvm_only && cfg->orig_method->klass->valuetype && !(cfg->orig_method->flags & METHOD_ATTRIBUTE_STATIC))
emit_unbox_tramp (ctx, method_name, method_type, method, cfg->method_index);
}
static void
-add_types (MonoLLVMModule *lmodule)
+add_types (MonoLLVMModule *module)
{
- lmodule->ptr_type = LLVMPointerType (sizeof (gpointer) == 8 ? LLVMInt64Type () : LLVMInt32Type (), 0);
+ module->ptr_type = LLVMPointerType (sizeof (gpointer) == 8 ? LLVMInt64Type () : LLVMInt32Type (), 0);
}
void
module = g_new0 (MonoLLVMModule, 1);
name = g_strdup_printf ("mono-%s", domain->friendly_name);
- module->module = LLVMModuleCreateWithName (name);
+ module->lmodule = LLVMModuleCreateWithName (name);
module->context = LLVMGetGlobalContext ();
- module->mono_ee = mono_llvm_create_ee (LLVMCreateModuleProviderForExistingModule (module->module), alloc_cb, emitted_cb, exception_cb, dlsym_cb, &module->ee);
+ module->mono_ee = mono_llvm_create_ee (LLVMCreateModuleProviderForExistingModule (module->lmodule), alloc_cb, emitted_cb, exception_cb, dlsym_cb, &module->ee);
- add_intrinsics (module->module);
+ add_intrinsics (module->lmodule);
add_types (module);
module->llvm_types = g_hash_table_new (NULL, NULL);
info = mono_find_jit_icall_by_name ("llvm_resume_unwind_trampoline");
g_assert (info);
- LLVMAddGlobalMapping (module->ee, LLVMGetNamedFunction (module->module, "llvm_resume_unwind_trampoline"), (void*)info->func);
+ LLVMAddGlobalMapping (module->ee, LLVMGetNamedFunction (module->lmodule, "llvm_resume_unwind_trampoline"), (void*)info->func);
mono_memory_barrier ();
void
mono_llvm_cleanup (void)
{
- if (aot_module.module)
- LLVMDisposeModule (aot_module.module);
+ MonoLLVMModule *module = &aot_module;
+
+ if (module->lmodule)
+ LLVMDisposeModule (module->lmodule);
- if (aot_module.context)
- LLVMContextDispose (aot_module.context);
+ if (module->context)
+ LLVMContextDispose (module->context);
}
void
void
mono_llvm_create_aot_module (MonoAssembly *assembly, const char *global_prefix, gboolean emit_dwarf, gboolean static_link, gboolean llvm_only)
{
- MonoLLVMModule *lmodule = &aot_module;
+ MonoLLVMModule *module = &aot_module;
/* Delete previous module */
- if (lmodule->plt_entries)
- g_hash_table_destroy (lmodule->plt_entries);
- if (lmodule->module)
- LLVMDisposeModule (lmodule->module);
-
- memset (lmodule, 0, sizeof (aot_module));
-
- lmodule->module = LLVMModuleCreateWithName ("aot");
- lmodule->assembly = assembly;
- lmodule->global_prefix = g_strdup (global_prefix);
- lmodule->got_symbol = g_strdup_printf ("%s_llvm_got", global_prefix);
- lmodule->eh_frame_symbol = g_strdup_printf ("%s_eh_frame", global_prefix);
- lmodule->get_method_symbol = g_strdup_printf ("%s_get_method", global_prefix);
- lmodule->get_unbox_tramp_symbol = g_strdup_printf ("%s_get_unbox_tramp", global_prefix);
- lmodule->external_symbols = TRUE;
- lmodule->emit_dwarf = emit_dwarf;
- lmodule->static_link = static_link;
- lmodule->llvm_only = llvm_only;
+ if (module->plt_entries)
+ g_hash_table_destroy (module->plt_entries);
+ if (module->lmodule)
+ LLVMDisposeModule (module->lmodule);
+
+ memset (module, 0, sizeof (aot_module));
+
+ module->lmodule = LLVMModuleCreateWithName ("aot");
+ module->assembly = assembly;
+ module->global_prefix = g_strdup (global_prefix);
+ module->got_symbol = g_strdup_printf ("%s_llvm_got", global_prefix);
+ module->eh_frame_symbol = g_strdup_printf ("%s_eh_frame", global_prefix);
+ module->get_method_symbol = g_strdup_printf ("%s_get_method", global_prefix);
+ module->get_unbox_tramp_symbol = g_strdup_printf ("%s_get_unbox_tramp", global_prefix);
+ module->external_symbols = TRUE;
+ module->emit_dwarf = emit_dwarf;
+ module->static_link = static_link;
+ module->llvm_only = llvm_only;
/* The first few entries are reserved */
- lmodule->max_got_offset = 16;
- lmodule->context = LLVMContextCreate ();
+ module->max_got_offset = 16;
+ module->context = LLVMContextCreate ();
- add_intrinsics (lmodule->module);
- add_types (lmodule);
+ add_intrinsics (module->lmodule);
+ add_types (module);
/* Add GOT */
/*
* its size is known in mono_llvm_emit_aot_module ().
*/
{
- LLVMTypeRef got_type = LLVMArrayType (lmodule->ptr_type, 0);
+ LLVMTypeRef got_type = LLVMArrayType (module->ptr_type, 0);
- aot_module.got_var = LLVMAddGlobal (lmodule->module, got_type, "mono_dummy_got");
- LLVMSetInitializer (lmodule->got_var, LLVMConstNull (got_type));
+ module->got_var = LLVMAddGlobal (module->lmodule, got_type, "mono_dummy_got");
+ LLVMSetInitializer (module->got_var, LLVMConstNull (got_type));
}
/* Add initialization array */
if (llvm_only) {
LLVMTypeRef inited_type = LLVMArrayType (LLVMInt8Type (), 0);
- aot_module.inited_var = LLVMAddGlobal (aot_module.module, inited_type, "mono_inited_tmp");
- LLVMSetInitializer (aot_module.inited_var, LLVMConstNull (inited_type));
+ module->inited_var = LLVMAddGlobal (aot_module.lmodule, inited_type, "mono_inited_tmp");
+ LLVMSetInitializer (module->inited_var, LLVMConstNull (inited_type));
}
if (llvm_only)
- emit_init_icall_wrappers (lmodule);
+ emit_init_icall_wrappers (module);
- emit_llvm_code_start (lmodule);
+ emit_llvm_code_start (module);
/* Add a dummy personality function */
if (!use_debug_personality) {
- LLVMValueRef personality = LLVMAddFunction (lmodule->module, default_personality_name, LLVMFunctionType (LLVMInt32Type (), NULL, 0, TRUE));
+ LLVMValueRef personality = LLVMAddFunction (module->lmodule, default_personality_name, LLVMFunctionType (LLVMInt32Type (), NULL, 0, TRUE));
LLVMSetLinkage (personality, LLVMExternalLinkage);
- mark_as_used (lmodule, personality);
+ mark_as_used (module, personality);
}
/* Add a reference to the c++ exception we throw/catch */
{
LLVMTypeRef exc = LLVMPointerType (LLVMInt8Type (), 0);
- lmodule->sentinel_exception = LLVMAddGlobal (lmodule->module, exc, "_ZTIPi");
- LLVMSetLinkage (lmodule->sentinel_exception, LLVMExternalLinkage);
- mono_llvm_set_is_constant (lmodule->sentinel_exception);
- }
-
- lmodule->llvm_types = g_hash_table_new (NULL, NULL);
- lmodule->plt_entries = g_hash_table_new (g_str_hash, g_str_equal);
- lmodule->plt_entries_ji = g_hash_table_new (NULL, NULL);
- lmodule->direct_callables = g_hash_table_new (g_str_hash, g_str_equal);
- lmodule->method_to_lmethod = g_hash_table_new (NULL, NULL);
- lmodule->idx_to_lmethod = g_hash_table_new (NULL, NULL);
- lmodule->idx_to_unbox_tramp = g_hash_table_new (NULL, NULL);
- lmodule->method_to_callers = g_hash_table_new (NULL, NULL);
+ module->sentinel_exception = LLVMAddGlobal (module->lmodule, exc, "_ZTIPi");
+ LLVMSetLinkage (module->sentinel_exception, LLVMExternalLinkage);
+ mono_llvm_set_is_constant (module->sentinel_exception);
+ }
+
+ module->llvm_types = g_hash_table_new (NULL, NULL);
+ module->plt_entries = g_hash_table_new (g_str_hash, g_str_equal);
+ module->plt_entries_ji = g_hash_table_new (NULL, NULL);
+ module->direct_callables = g_hash_table_new (g_str_hash, g_str_equal);
+ module->method_to_lmethod = g_hash_table_new (NULL, NULL);
+ module->idx_to_lmethod = g_hash_table_new (NULL, NULL);
+ module->idx_to_unbox_tramp = g_hash_table_new (NULL, NULL);
+ module->method_to_callers = g_hash_table_new (NULL, NULL);
}
static LLVMValueRef
void
mono_llvm_emit_aot_file_info (MonoAotFileInfo *info, gboolean has_jitted_code)
{
- MonoLLVMModule *lmodule = &aot_module;
+ MonoLLVMModule *module = &aot_module;
/* Save these for later */
- memcpy (&lmodule->aot_info, info, sizeof (MonoAotFileInfo));
- lmodule->has_jitted_code = has_jitted_code;
+ memcpy (&module->aot_info, info, sizeof (MonoAotFileInfo));
+ module->has_jitted_code = has_jitted_code;
}
/*
void
mono_llvm_emit_aot_data (const char *symbol, guint8 *data, int data_len)
{
- MonoLLVMModule *lmodule = &aot_module;
+ MonoLLVMModule *module = &aot_module;
LLVMTypeRef type;
LLVMValueRef d;
type = LLVMArrayType (LLVMInt8Type (), data_len);
- d = LLVMAddGlobal (lmodule->module, type, symbol);
+ d = LLVMAddGlobal (module->lmodule, type, symbol);
LLVMSetVisibility (d, LLVMHiddenVisibility);
LLVMSetLinkage (d, LLVMInternalLinkage);
LLVMSetInitializer (d, mono_llvm_create_constant_data_array (data, data_len));
/* Add a reference to a global defined in JITted code */
static LLVMValueRef
-AddJitGlobal (MonoLLVMModule *lmodule, LLVMTypeRef type, const char *name)
+AddJitGlobal (MonoLLVMModule *module, LLVMTypeRef type, const char *name)
{
char *s;
LLVMValueRef v;
- s = g_strdup_printf ("%s%s", lmodule->global_prefix, name);
- v = LLVMAddGlobal (lmodule->module, LLVMInt8Type (), s);
+ s = g_strdup_printf ("%s%s", module->global_prefix, name);
+ v = LLVMAddGlobal (module->lmodule, LLVMInt8Type (), s);
g_free (s);
return v;
}
static void
-emit_aot_file_info (MonoLLVMModule *lmodule)
+emit_aot_file_info (MonoLLVMModule *module)
{
LLVMTypeRef file_info_type;
LLVMTypeRef *eltypes, eltype;
LLVMValueRef *fields;
int i, nfields, tindex;
MonoAotFileInfo *info;
+ LLVMModuleRef lmodule = module->lmodule;
- info = &lmodule->aot_info;
+ info = &module->aot_info;
/* Create an LLVM type to represent MonoAotFileInfo */
nfields = 2 + MONO_AOT_FILE_INFO_NUM_SYMBOLS + 14 + 4;
for (i = 0; i < 4; ++i)
eltypes [tindex ++] = LLVMArrayType (LLVMInt32Type (), MONO_AOT_TRAMP_NUM);
g_assert (tindex == nfields);
- file_info_type = LLVMStructCreateNamed (aot_module.context, "MonoAotFileInfo");
+ file_info_type = LLVMStructCreateNamed (module->context, "MonoAotFileInfo");
LLVMStructSetBody (file_info_type, eltypes, nfields, FALSE);
- info_var = LLVMAddGlobal (lmodule->module, file_info_type, "mono_aot_file_info");
- if (lmodule->static_link) {
+ info_var = LLVMAddGlobal (lmodule, file_info_type, "mono_aot_file_info");
+ if (module->static_link) {
LLVMSetVisibility (info_var, LLVMHiddenVisibility);
LLVMSetLinkage (info_var, LLVMInternalLinkage);
}
* for symbols defined in the .s file emitted by the aot compiler.
*/
eltype = eltypes [tindex];
- if (lmodule->llvm_only)
+ if (module->llvm_only)
fields [tindex ++] = LLVMConstNull (eltype);
else
- fields [tindex ++] = AddJitGlobal (lmodule, eltype, "jit_got");
- fields [tindex ++] = lmodule->got_var;
+ fields [tindex ++] = AddJitGlobal (module, eltype, "jit_got");
+ fields [tindex ++] = module->got_var;
/* llc defines this directly */
- if (!lmodule->llvm_only) {
- fields [tindex ++] = LLVMAddGlobal (lmodule->module, eltype, lmodule->eh_frame_symbol);
+ if (!module->llvm_only) {
+ fields [tindex ++] = LLVMAddGlobal (lmodule, eltype, module->eh_frame_symbol);
fields [tindex ++] = LLVMConstNull (eltype);
fields [tindex ++] = LLVMConstNull (eltype);
} else {
fields [tindex ++] = LLVMConstNull (eltype);
- fields [tindex ++] = lmodule->get_method;
- fields [tindex ++] = lmodule->get_unbox_tramp;
+ fields [tindex ++] = module->get_method;
+ fields [tindex ++] = module->get_unbox_tramp;
}
- if (lmodule->has_jitted_code) {
- fields [tindex ++] = AddJitGlobal (lmodule, eltype, "jit_code_start");
- fields [tindex ++] = AddJitGlobal (lmodule, eltype, "jit_code_end");
+ if (module->has_jitted_code) {
+ fields [tindex ++] = AddJitGlobal (module, eltype, "jit_code_start");
+ fields [tindex ++] = AddJitGlobal (module, eltype, "jit_code_end");
} else {
fields [tindex ++] = LLVMConstNull (eltype);
fields [tindex ++] = LLVMConstNull (eltype);
}
- if (!lmodule->llvm_only)
- fields [tindex ++] = AddJitGlobal (lmodule, eltype, "method_addresses");
+ if (!module->llvm_only)
+ fields [tindex ++] = AddJitGlobal (module, eltype, "method_addresses");
else
fields [tindex ++] = LLVMConstNull (eltype);
- fields [tindex ++] = LLVMGetNamedGlobal (lmodule->module, "blob");
- fields [tindex ++] = LLVMGetNamedGlobal (lmodule->module, "class_name_table");
- fields [tindex ++] = LLVMGetNamedGlobal (lmodule->module, "class_info_offsets");
- fields [tindex ++] = LLVMGetNamedGlobal (lmodule->module, "method_info_offsets");
- fields [tindex ++] = LLVMGetNamedGlobal (lmodule->module, "ex_info_offsets");
- fields [tindex ++] = LLVMGetNamedGlobal (lmodule->module, "extra_method_info_offsets");
- fields [tindex ++] = LLVMGetNamedGlobal (lmodule->module, "extra_method_table");
- fields [tindex ++] = LLVMGetNamedGlobal (lmodule->module, "got_info_offsets");
- fields [tindex ++] = LLVMGetNamedGlobal (lmodule->module, "llvm_got_info_offsets");
+ fields [tindex ++] = LLVMGetNamedGlobal (lmodule, "blob");
+ fields [tindex ++] = LLVMGetNamedGlobal (lmodule, "class_name_table");
+ fields [tindex ++] = LLVMGetNamedGlobal (lmodule, "class_info_offsets");
+ fields [tindex ++] = LLVMGetNamedGlobal (lmodule, "method_info_offsets");
+ fields [tindex ++] = LLVMGetNamedGlobal (lmodule, "ex_info_offsets");
+ fields [tindex ++] = LLVMGetNamedGlobal (lmodule, "extra_method_info_offsets");
+ fields [tindex ++] = LLVMGetNamedGlobal (lmodule, "extra_method_table");
+ fields [tindex ++] = LLVMGetNamedGlobal (lmodule, "got_info_offsets");
+ fields [tindex ++] = LLVMGetNamedGlobal (lmodule, "llvm_got_info_offsets");
/* Not needed (mem_end) */
fields [tindex ++] = LLVMConstNull (eltype);
- fields [tindex ++] = LLVMGetNamedGlobal (lmodule->module, "image_table");
- fields [tindex ++] = LLVMGetNamedGlobal (lmodule->module, "assembly_guid");
- fields [tindex ++] = LLVMGetNamedGlobal (lmodule->module, "runtime_version");
+ fields [tindex ++] = LLVMGetNamedGlobal (lmodule, "image_table");
+ fields [tindex ++] = LLVMGetNamedGlobal (lmodule, "assembly_guid");
+ fields [tindex ++] = LLVMGetNamedGlobal (lmodule, "runtime_version");
if (info->trampoline_size [0]) {
- fields [tindex ++] = AddJitGlobal (lmodule, eltype, "specific_trampolines");
- fields [tindex ++] = AddJitGlobal (lmodule, eltype, "static_rgctx_trampolines");
- fields [tindex ++] = AddJitGlobal (lmodule, eltype, "imt_thunks");
- fields [tindex ++] = AddJitGlobal (lmodule, eltype, "gsharedvt_arg_trampolines");
+ fields [tindex ++] = AddJitGlobal (module, eltype, "specific_trampolines");
+ fields [tindex ++] = AddJitGlobal (module, eltype, "static_rgctx_trampolines");
+ fields [tindex ++] = AddJitGlobal (module, eltype, "imt_thunks");
+ fields [tindex ++] = AddJitGlobal (module, eltype, "gsharedvt_arg_trampolines");
} else {
fields [tindex ++] = LLVMConstNull (eltype);
fields [tindex ++] = LLVMConstNull (eltype);
fields [tindex ++] = LLVMConstNull (eltype);
fields [tindex ++] = LLVMConstNull (eltype);
}
- if (lmodule->static_link)
- fields [tindex ++] = AddJitGlobal (lmodule, eltype, "globals");
+ if (module->static_link)
+ fields [tindex ++] = AddJitGlobal (module, eltype, "globals");
else
fields [tindex ++] = LLVMConstNull (eltype);
- fields [tindex ++] = LLVMGetNamedGlobal (lmodule->module, "assembly_name");
- if (!lmodule->llvm_only) {
- fields [tindex ++] = AddJitGlobal (lmodule, eltype, "plt");
- fields [tindex ++] = AddJitGlobal (lmodule, eltype, "plt_end");
- fields [tindex ++] = AddJitGlobal (lmodule, eltype, "unwind_info");
- fields [tindex ++] = AddJitGlobal (lmodule, eltype, "unbox_trampolines");
- fields [tindex ++] = AddJitGlobal (lmodule, eltype, "unbox_trampolines_end");
- fields [tindex ++] = AddJitGlobal (lmodule, eltype, "unbox_trampoline_addresses");
+ fields [tindex ++] = LLVMGetNamedGlobal (lmodule, "assembly_name");
+ if (!module->llvm_only) {
+ fields [tindex ++] = AddJitGlobal (module, eltype, "plt");
+ fields [tindex ++] = AddJitGlobal (module, eltype, "plt_end");
+ fields [tindex ++] = AddJitGlobal (module, eltype, "unwind_info");
+ fields [tindex ++] = AddJitGlobal (module, eltype, "unbox_trampolines");
+ fields [tindex ++] = AddJitGlobal (module, eltype, "unbox_trampolines_end");
+ fields [tindex ++] = AddJitGlobal (module, eltype, "unbox_trampoline_addresses");
} else {
fields [tindex ++] = LLVMConstNull (eltype);
fields [tindex ++] = LLVMConstNull (eltype);
LLVMSetInitializer (info_var, LLVMConstNamedStruct (file_info_type, fields, nfields));
- if (lmodule->static_link) {
+ if (module->static_link) {
char *s, *p;
LLVMValueRef var;
- s = g_strdup_printf ("mono_aot_module_%s_info", lmodule->assembly->aname.name);
+ s = g_strdup_printf ("mono_aot_module_%s_info", module->assembly->aname.name);
/* Get rid of characters which cannot occur in symbols */
p = s;
for (p = s; *p; ++p) {
if (!(isalnum (*p) || *p == '_'))
*p = '_';
}
- var = LLVMAddGlobal (lmodule->module, LLVMPointerType (LLVMInt8Type (), 0), s);
+ var = LLVMAddGlobal (module->lmodule, LLVMPointerType (LLVMInt8Type (), 0), s);
g_free (s);
- LLVMSetInitializer (var, LLVMConstBitCast (LLVMGetNamedGlobal (lmodule->module, "mono_aot_file_info"), LLVMPointerType (LLVMInt8Type (), 0)));
+ LLVMSetInitializer (var, LLVMConstBitCast (LLVMGetNamedGlobal (module->lmodule, "mono_aot_file_info"), LLVMPointerType (LLVMInt8Type (), 0)));
LLVMSetLinkage (var, LLVMExternalLinkage);
}
}
* Create the real got variable and replace all uses of the dummy variable with
* the real one.
*/
- got_type = LLVMArrayType (aot_module.ptr_type, module->max_got_offset + 1);
- real_got = LLVMAddGlobal (aot_module.module, got_type, aot_module.got_symbol);
+ got_type = LLVMArrayType (module->ptr_type, module->max_got_offset + 1);
+ real_got = LLVMAddGlobal (module->lmodule, got_type, module->got_symbol);
LLVMSetInitializer (real_got, LLVMConstNull (got_type));
if (module->external_symbols) {
LLVMSetLinkage (real_got, LLVMExternalLinkage);
} else {
LLVMSetLinkage (real_got, LLVMInternalLinkage);
}
- mono_llvm_replace_uses_of (aot_module.got_var, real_got);
+ mono_llvm_replace_uses_of (module->got_var, real_got);
mark_as_used (&aot_module, real_got);
/* Delete the dummy got so it doesn't become a global */
- LLVMDeleteGlobal (aot_module.got_var);
- aot_module.got_var = real_got;
+ LLVMDeleteGlobal (module->got_var);
+ module->got_var = real_got;
/*
* Same for the init_var
*/
- if (aot_module.llvm_only) {
+ if (module->llvm_only) {
inited_type = LLVMArrayType (LLVMInt8Type (), module->max_inited_idx + 1);
- real_inited = LLVMAddGlobal (aot_module.module, inited_type, "mono_inited");
+ real_inited = LLVMAddGlobal (module->lmodule, inited_type, "mono_inited");
LLVMSetInitializer (real_inited, LLVMConstNull (inited_type));
LLVMSetLinkage (real_inited, LLVMInternalLinkage);
- mono_llvm_replace_uses_of (aot_module.inited_var, real_inited);
- LLVMDeleteGlobal (aot_module.inited_var);
+ mono_llvm_replace_uses_of (module->inited_var, real_inited);
+ LLVMDeleteGlobal (module->inited_var);
}
- if (aot_module.llvm_only) {
+ if (module->llvm_only) {
emit_get_method (&aot_module);
emit_get_unbox_tramp (&aot_module);
}
* their bodies, but that couldn't handle the case when a method fails to compile
* with llvm.
*/
- if (aot_module.llvm_only) {
+ if (module->llvm_only) {
GHashTableIter iter;
MonoMethod *method;
GSList *callers, *l;
- g_hash_table_iter_init (&iter, aot_module.method_to_callers);
+ g_hash_table_iter_init (&iter, module->method_to_callers);
while (g_hash_table_iter_next (&iter, (void**)&method, (void**)&callers)) {
LLVMValueRef lmethod;
MonoJumpInfo *ji;
LLVMValueRef callee;
- g_hash_table_iter_init (&iter, aot_module.plt_entries_ji);
+ g_hash_table_iter_init (&iter, module->plt_entries_ji);
while (g_hash_table_iter_next (&iter, (void**)&ji, (void**)&callee)) {
if (mono_aot_is_direct_callable (ji)) {
LLVMValueRef lmethod;
{
char *verifier_err;
- if (LLVMVerifyModule (aot_module.module, LLVMReturnStatusAction, &verifier_err)) {
+ if (LLVMVerifyModule (module->module, LLVMReturnStatusAction, &verifier_err)) {
g_assert_not_reached ();
}
}
#endif
- LLVMWriteBitcodeToFile (aot_module.module, filename);
+ LLVMWriteBitcodeToFile (module->lmodule, filename);
}
/* Debugging support */
static void
-emit_dbg_info (MonoLLVMModule *lmodule, const char *filename, const char *cu_name)
+emit_dbg_info (MonoLLVMModule *module, const char *filename, const char *cu_name)
{
- LLVMModuleRef module = lmodule->module;
+ LLVMModuleRef lmodule = module->lmodule;
LLVMValueRef args [16], cu_args [16], cu, ver;
int n_cuargs;
char *build_info, *s, *dir;
* and the abbrev indexes will not be correct since llvm has added its own
* abbrevs.
*/
- if (!lmodule->emit_dwarf)
+ if (!module->emit_dwarf)
return;
/*
cu_args [n_cuargs ++] = LLVMMDNode (args, 0);
cu_args [n_cuargs ++] = LLVMMDNode (args, 0);
/* Subprograms */
- if (lmodule->subprogram_mds) {
+ if (module->subprogram_mds) {
LLVMValueRef *mds;
int i;
- mds = g_new0 (LLVMValueRef, lmodule->subprogram_mds->len);
- for (i = 0; i < lmodule->subprogram_mds->len; ++i)
- mds [i] = g_ptr_array_index (lmodule->subprogram_mds, i);
- cu_args [n_cuargs ++] = LLVMMDNode (mds, lmodule->subprogram_mds->len);
+ mds = g_new0 (LLVMValueRef, module->subprogram_mds->len);
+ for (i = 0; i < module->subprogram_mds->len; ++i)
+ mds [i] = g_ptr_array_index (module->subprogram_mds, i);
+ cu_args [n_cuargs ++] = LLVMMDNode (mds, module->subprogram_mds->len);
} else {
cu_args [n_cuargs ++] = LLVMMDNode (args, 0);
}
/* DebugEmissionKind = FullDebug */
cu_args [n_cuargs ++] = LLVMConstInt (LLVMInt32Type (), 1, FALSE);
cu = LLVMMDNode (cu_args, n_cuargs);
- LLVMAddNamedMetadataOperand (module, "llvm.dbg.cu", cu);
+ LLVMAddNamedMetadataOperand (lmodule, "llvm.dbg.cu", cu);
args [0] = LLVMConstInt (LLVMInt32Type (), 1, FALSE);
args [1] = LLVMMDString ("Dwarf Version", strlen ("Dwarf Version"));
args [2] = LLVMConstInt (LLVMInt32Type (), 2, FALSE);
ver = LLVMMDNode (args, 3);
- LLVMAddNamedMetadataOperand (module, "llvm.module.flags", ver);
+ LLVMAddNamedMetadataOperand (lmodule, "llvm.module.flags", ver);
args [0] = LLVMConstInt (LLVMInt32Type (), 1, FALSE);
args [1] = LLVMMDString ("Debug Info Version", strlen ("Debug Info Version"));
args [2] = LLVMConstInt (LLVMInt32Type (), 1, FALSE);
ver = LLVMMDNode (args, 3);
- LLVMAddNamedMetadataOperand (module, "llvm.module.flags", ver);
+ LLVMAddNamedMetadataOperand (lmodule, "llvm.module.flags", ver);
}
static LLVMValueRef
emit_dbg_subprogram (EmitContext *ctx, MonoCompile *cfg, LLVMValueRef method, const char *name)
{
- MonoLLVMModule *module = ctx->lmodule;
+ MonoLLVMModule *module = ctx->module;
MonoDebugMethodInfo *minfo = ctx->minfo;
char *source_file, *dir, *filename;
LLVMValueRef md, args [16], ctx_args [16], md_args [64], type_args [16], ctx_md, type_md;