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][mini] Prefer calling llvmaot compiled method instead of inlining it with JIT #107401

Merged
merged 2 commits into from
Sep 16, 2024
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
2 changes: 2 additions & 0 deletions src/mono/mono/mini/aot-compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -7607,6 +7607,8 @@ emit_method_info (MonoAotCompile *acfg, MonoCompile *cfg)
flags |= MONO_AOT_METHOD_FLAG_HAS_CTX;
if (cfg->interp_entry_only)
flags |= MONO_AOT_METHOD_FLAG_INTERP_ENTRY_ONLY;
if (cfg->uses_simd_intrinsics && cfg->compile_llvm)
flags |= MONO_AOT_METHOD_FLAG_HAS_LLVM_INTRINSICS;
/* Saved into another table so it can be accessed without having access to this data */
cfg->aot_method_flags = flags;

Expand Down
31 changes: 21 additions & 10 deletions src/mono/mono/mini/aot-runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -4441,16 +4441,15 @@ load_method (MonoAotModule *amodule, MonoImage *image, MonoMethod *method, guint
g_free (full_name);
}

if (mono_llvm_only) {
guint8 flags = amodule->method_flags_table [method_index];
/* The caller needs to looks this up, but its hard to do without constructing the full MonoJitInfo, so save it here */
if (flags & (MONO_AOT_METHOD_FLAG_GSHAREDVT_VARIABLE | MONO_AOT_METHOD_FLAG_INTERP_ENTRY_ONLY)) {
mono_aot_lock ();
if (!code_to_method_flags)
code_to_method_flags = g_hash_table_new (NULL, NULL);
g_hash_table_insert (code_to_method_flags, code, GUINT_TO_POINTER (flags));
mono_aot_unlock ();
}
guint8 flags = amodule->method_flags_table [method_index];
/* The caller needs to looks this up, but its hard to do without constructing the full MonoJitInfo, so save it here */
if ((mono_llvm_only && (flags & (MONO_AOT_METHOD_FLAG_GSHAREDVT_VARIABLE | MONO_AOT_METHOD_FLAG_INTERP_ENTRY_ONLY))) ||
(flags & MONO_AOT_METHOD_FLAG_HAS_LLVM_INTRINSICS)) {
mono_aot_lock ();
if (!code_to_method_flags)
code_to_method_flags = g_hash_table_new (NULL, NULL);
g_hash_table_insert (code_to_method_flags, code, GUINT_TO_POINTER (flags));
mono_aot_unlock ();
}

init_plt (amodule);
Expand Down Expand Up @@ -6547,6 +6546,12 @@ mono_aot_get_method_flags (guint8 *code)
return (MonoAotMethodFlags)flags;
}

MonoAotFileFlags
mono_aot_get_module_flags (gpointer aot_module)
{
return ((MonoAotModule*)aot_module)->info.flags;
}

#else
/* AOT disabled */

Expand Down Expand Up @@ -6747,4 +6752,10 @@ mono_aot_get_method_flags (guint8 *code)
return MONO_AOT_METHOD_FLAG_NONE;
}

MonoAotFileFlags
mono_aot_get_module_flags (gpointer aot_module)
{
return 0;
}

#endif
2 changes: 2 additions & 0 deletions src/mono/mono/mini/aot-runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ typedef enum {
MONO_AOT_METHOD_FLAG_HAS_PATCHES = 4,
MONO_AOT_METHOD_FLAG_HAS_CTX = 8,
MONO_AOT_METHOD_FLAG_INTERP_ENTRY_ONLY = 16,
MONO_AOT_METHOD_FLAG_HAS_LLVM_INTRINSICS = 32,
} MonoAotMethodFlags;

#undef DEBUG_AOT_NAME_TABLE
Expand Down Expand Up @@ -282,6 +283,7 @@ guint32 mono_aot_find_method_index (MonoMethod *method);
gboolean mono_aot_init_llvm_method (gpointer aot_module, gpointer method_info, MonoClass *init_class, MonoError *error);
GHashTable *mono_aot_get_weak_field_indexes (MonoImage *image);
MonoAotMethodFlags mono_aot_get_method_flags (guint8 *code);
MonoAotFileFlags mono_aot_get_module_flags (gpointer aot_module);

#ifdef MONO_ARCH_CODE_EXEC_ONLY
typedef guint32 (*MonoAotResolvePltInfoOffset)(gpointer amodule, guint32 plt_entry_index);
Expand Down
14 changes: 14 additions & 0 deletions src/mono/mono/mini/method-to-ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -4179,6 +4179,20 @@ mono_method_check_inlining (MonoCompile *cfg, MonoMethod *method)
if (method_does_not_return (method))
return FALSE;

MonoAotModule *amodule = m_class_get_image (method->klass)->aot_module;
// If method is present in aot image compiled with llvm and it uses hw intrinsics we don't inline it,
// since we might not have support for those intrinsics with JIT
if (amodule && (amodule != AOT_MODULE_NOT_FOUND) && (mono_aot_get_module_flags (amodule) & MONO_AOT_FILE_FLAG_WITH_LLVM)) {
ERROR_DECL (error);
mono_class_init_internal (method->klass);
gpointer addr = mono_aot_get_method (method, error);
if (addr && is_ok (error)) {
MonoAotMethodFlags flags = mono_aot_get_method_flags (addr);
if (flags & MONO_AOT_METHOD_FLAG_HAS_LLVM_INTRINSICS)
return FALSE;
}
}

return TRUE;
}

Expand Down
Loading