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] Enable deduplication of runtime invoke wrappers #84304

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
42 changes: 28 additions & 14 deletions src/mono/mono/mini/aot-compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -4283,9 +4283,35 @@ get_method_index (MonoAotCompile *acfg, MonoMethod *method)
return index - 1;
}

static gboolean
kotlarmilos marked this conversation as resolved.
Show resolved Hide resolved
collect_dedup_method (MonoAotCompile *acfg, MonoMethod *method)
{
// Check if the dedup is enabled, and if the current method can be deduplicated
if ((acfg->aot_opts.dedup || acfg->aot_opts.dedup_include) && mono_aot_can_dedup (method)) {
if (!acfg->dedup_emit_mode) {
/* Remember for later */
if (!g_hash_table_lookup (dedup_methods, method))
g_hash_table_insert (dedup_methods, method, method);
} else if (acfg->aot_opts.dedup_include) {
// Allow emitting collected methods
return FALSE;
}
return TRUE;
}
return FALSE;
}



static int
add_method_full (MonoAotCompile *acfg, MonoMethod *method, gboolean extra, int depth)
{
if (collect_dedup_method (acfg, method))
return -1;

if (acfg->aot_opts.log_generics && extra)
aot_printf (acfg, "%*sAdding method %s.\n", depth, "", mono_method_get_full_name (method));

int index;

index = GPOINTER_TO_UINT (g_hash_table_lookup (acfg->method_indexes, method));
Expand Down Expand Up @@ -4372,20 +4398,6 @@ add_extra_method_full (MonoAotCompile *acfg, MonoMethod *method, gboolean prefer
mono_error_assert_ok (error);
}

if ((acfg->aot_opts.dedup || acfg->aot_opts.dedup_include) && mono_aot_can_dedup (method)) {
if (acfg->aot_opts.dedup) {
/* Don't emit instances */
return;
} else if (!acfg->dedup_emit_mode) {
/* Remember for later */
if (!g_hash_table_lookup (dedup_methods, method))
g_hash_table_insert (dedup_methods, method, method);
}
}

if (acfg->aot_opts.log_generics)
aot_printf (acfg, "%*sAdding method %s.\n", depth, "", mono_method_get_full_name (method));

add_method_full (acfg, method, TRUE, depth);
}

Expand Down Expand Up @@ -14868,6 +14880,8 @@ aot_assembly (MonoAssembly *ass, guint32 jit_opts, MonoAotOptions *aot_options)
g_hash_table_iter_init (&iter, dedup_methods);
while (g_hash_table_iter_next (&iter, (gpointer *)&key, (gpointer *)&method))
add_method_full (acfg, method, TRUE, 0);
// Disable dedup_emit_mode to restrict emitting additional methods which are not collected in dedup_methods
acfg->dedup_emit_mode = FALSE;
}

{
Expand Down
4 changes: 0 additions & 4 deletions src/mono/mono/mini/aot-runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -4542,11 +4542,7 @@ mono_aot_can_dedup (MonoMethod *method)
/* Use a set of wrappers/instances which work and useful */
switch (method->wrapper_type) {
case MONO_WRAPPER_RUNTIME_INVOKE:
#ifdef TARGET_WASM
return TRUE;
#else
return FALSE;
#endif
break;
case MONO_WRAPPER_OTHER: {
WrapperInfo *info = mono_marshal_get_wrapper_info (method);
Expand Down