Skip to content

Commit

Permalink
[mono][mini] Prefer llvm compiled method only if it uses simd intrinsics
Browse files Browse the repository at this point in the history
We include a new flag when compiling aot method. When loading aot method, we will include mapping from code to flags so we can look it up later.
  • Loading branch information
BrzVlad committed Sep 11, 2024
1 parent 8d5107c commit 335464b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
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
19 changes: 9 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
1 change: 1 addition & 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
10 changes: 7 additions & 3 deletions src/mono/mono/mini/method-to-ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -4180,13 +4180,17 @@ mono_method_check_inlining (MonoCompile *cfg, MonoMethod *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 method is present in aot image compiled with llvm, we don't inline it
if (addr && is_ok (error))
return FALSE;
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

0 comments on commit 335464b

Please sign in to comment.