Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mono][aot] Free LLVM module after AOT. #81014

Merged
merged 1 commit into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/mono/mono/mini/aot-compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -13744,7 +13744,13 @@ got_info_free (GotInfo *info)
static void
acfg_free (MonoAotCompile *acfg)
{
mono_img_writer_destroy (acfg->w);
#ifdef ENABLE_LLVM
if (acfg->aot_opts.llvm)
mono_llvm_free_aot_module ();
#endif

if (acfg->w)
mono_img_writer_destroy (acfg->w);
for (guint32 i = 0; i < acfg->nmethods; ++i)
if (acfg->cfgs [i])
mono_destroy_compile (acfg->cfgs [i]);
Expand Down Expand Up @@ -14441,9 +14447,11 @@ aot_assembly (MonoAssembly *ass, guint32 jit_opts, MonoAotOptions *aot_options)

dedup_skip_methods (acfg);

if (acfg->dedup_collect_only)
if (acfg->dedup_collect_only) {
/* We only collected methods from this assembly */
acfg_free (acfg);
return 0;
}

current_acfg = NULL;

Expand Down
36 changes: 30 additions & 6 deletions src/mono/mono/mini/mini-llvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,12 @@ create_address (MonoLLVMModule *module, LLVMValueRef value, LLVMTypeRef type)
return res;
}

static void
address_free (gpointer addr)
{
g_free (addr);
}

typedef struct {
int32_t size;
uint32_t align;
Expand Down Expand Up @@ -12996,11 +13002,6 @@ mono_llvm_create_aot_module (MonoAssembly *assembly, const char *global_prefix,
gboolean llvm_only = (flags & LLVM_MODULE_FLAG_LLVM_ONLY) ? 1 : 0;
gboolean interp = (flags & LLVM_MODULE_FLAG_INTERP) ? 1 : 0;

/* Delete previous module */
g_hash_table_destroy (module->plt_entries);
if (module->lmodule)
LLVMDisposeModule (module->lmodule);

memset (module, 0, sizeof (aot_module));

module->lmodule = LLVMModuleCreateWithName ("aot");
Expand All @@ -13019,7 +13020,7 @@ mono_llvm_create_aot_module (MonoAssembly *assembly, const char *global_prefix,
module->max_got_offset = initial_got_size;
module->context = LLVMGetGlobalContext ();
module->cfgs = g_ptr_array_new ();
module->aotconst_vars = g_hash_table_new (NULL, NULL);
module->aotconst_vars = g_hash_table_new_full (NULL, NULL, NULL, address_free);
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);
Expand Down Expand Up @@ -13141,6 +13142,29 @@ mono_llvm_create_aot_module (MonoAssembly *assembly, const char *global_prefix,
}
}

void
mono_llvm_free_aot_module (void)
{
MonoLLVMModule *module = &aot_module;

if (module->lmodule)
LLVMDisposeModule (module->lmodule);

g_hash_table_destroy (module->aotconst_vars);
g_hash_table_destroy (module->llvm_types);
g_hash_table_destroy (module->plt_entries);
g_hash_table_destroy (module->plt_entries_ji);
g_hash_table_destroy (module->direct_callables);
g_hash_table_destroy (module->idx_to_lmethod);
g_hash_table_destroy (module->method_to_lmethod);
g_hash_table_destroy (module->method_to_call_info);
g_hash_table_destroy (module->idx_to_unbox_tramp);
g_hash_table_destroy (module->no_method_table_lmethods);

g_ptr_array_free (module->cfgs, TRUE);
g_ptr_array_free (module->callsite_list, TRUE);
}

void
mono_llvm_fixup_aot_module (void)
{
Expand Down
1 change: 1 addition & 0 deletions src/mono/mono/mini/mini-llvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ void mono_llvm_init (gboolean enable_jit);
void mono_llvm_emit_method (MonoCompile *cfg);
void mono_llvm_emit_call (MonoCompile *cfg, MonoCallInst *call);
void mono_llvm_create_aot_module (MonoAssembly *assembly, const char *global_prefix, int initial_got_size, LLVMModuleFlags flags);
void mono_llvm_free_aot_module (void);
void mono_llvm_emit_aot_module (const char *filename, const char *cu_name);
void mono_llvm_emit_aot_file_info (MonoAotFileInfo *info, gboolean has_jitted_code);
gpointer mono_llvm_emit_aot_data (const char *symbol, guint8 *data, int data_len);
Expand Down