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][jit] Optimize JIT time on platforms without SIMD support. #99485

Merged
merged 1 commit into from
Mar 11, 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
16 changes: 6 additions & 10 deletions src/mono/mono/mini/intrinsics.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,9 @@ mini_emit_inst_for_ctor (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignat
if (!(cfg->opt & MONO_OPT_INTRINS))
return ins;

if (cfg->opt & MONO_OPT_SIMD) {
ins = mono_emit_simd_intrinsics (cfg, cmethod, fsig, args);
if (ins)
return ins;
}
ins = mono_emit_simd_intrinsics (cfg, cmethod, fsig, args);
if (ins)
return ins;

ins = mono_emit_common_intrinsics (cfg, cmethod, fsig, args);
if (ins)
Expand Down Expand Up @@ -2093,11 +2091,9 @@ mini_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSign
}
}

if (cfg->opt & MONO_OPT_SIMD) {
ins = mono_emit_simd_intrinsics (cfg, cmethod, fsig, args);
if (ins)
return ins;
}
ins = mono_emit_simd_intrinsics (cfg, cmethod, fsig, args);
if (ins)
return ins;

ins = mono_emit_common_intrinsics (cfg, cmethod, fsig, args);
if (ins)
Expand Down
6 changes: 3 additions & 3 deletions src/mono/mono/mini/method-to-ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -4735,11 +4735,11 @@ mini_inline_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *
}

static gboolean
aggressive_inline_method (MonoMethod *cmethod)
aggressive_inline_method (MonoCompile *cfg, MonoMethod *cmethod)
{
gboolean aggressive_inline = m_method_is_aggressive_inlining (cmethod);
if (aggressive_inline)
aggressive_inline = !mono_simd_unsupported_aggressive_inline_intrinsic_type (cmethod);
aggressive_inline = !mono_simd_unsupported_aggressive_inline_intrinsic_type (cfg, cmethod);
return aggressive_inline;
}

Expand Down Expand Up @@ -4868,7 +4868,7 @@ inline_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig,
cfg->disable_inline = prev_disable_inline;
cfg->inline_depth --;

if ((costs >= 0 && costs < 60) || inline_always || (costs >= 0 && aggressive_inline_method (cmethod))) {
if ((costs >= 0 && costs < 60) || inline_always || (costs >= 0 && aggressive_inline_method (cfg, cmethod))) {
if (cfg->verbose_level > 2)
printf ("INLINE END %s -> %s\n", mono_method_full_name (cfg->method, TRUE), mono_method_full_name (cmethod, TRUE));

Expand Down
4 changes: 0 additions & 4 deletions src/mono/mono/mini/mini-ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -804,8 +804,6 @@ MINI_OP(OP_LDTOKEN_FIELD, "ldtoken_field", VREG, VREG, NONE)

/* SIMD opcodes. */

#if defined(TARGET_X86) || defined(TARGET_AMD64) || defined(TARGET_WASM) || defined(TARGET_ARM64)

MINI_OP(OP_ICONV_TO_R4_RAW, "iconv_to_r4_raw", FREG, IREG, NONE)

/* Extract an element from a vector with a constant lane index.
Expand Down Expand Up @@ -853,8 +851,6 @@ MINI_OP(OP_EXPAND_R4, "expand_r4", XREG, FREG, NONE)
MINI_OP(OP_EXPAND_I8, "expand_i8", XREG, IREG, NONE)
MINI_OP(OP_EXPAND_R8, "expand_r8", XREG, FREG, NONE)

#endif

// wasm specific SIMD v128

#if defined(TARGET_WASM)
Expand Down
3 changes: 3 additions & 0 deletions src/mono/mono/mini/mini.c
Original file line number Diff line number Diff line change
Expand Up @@ -3037,6 +3037,9 @@ is_simd_supported (MonoCompile *cfg)
{
#ifdef DISABLE_SIMD
return FALSE;
#endif
#ifndef MONO_ARCH_SIMD_INTRINSICS
return FALSE;
#endif
// FIXME: Clean this up
#ifdef TARGET_WASM
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/mini/mini.h
Original file line number Diff line number Diff line change
Expand Up @@ -2962,7 +2962,7 @@ MonoInst* mono_emit_common_intrinsics (MonoCompile *cfg, MonoMethod *cmethod,
MonoInst* mono_emit_simd_intrinsics (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args);
MonoInst* mono_emit_simd_field_load (MonoCompile *cfg, MonoClassField *field, MonoInst *addr);
void mono_simd_intrinsics_init (void);
gboolean mono_simd_unsupported_aggressive_inline_intrinsic_type (MonoMethod *cmethod);
gboolean mono_simd_unsupported_aggressive_inline_intrinsic_type (MonoCompile *cfg, MonoMethod *cmethod);

MonoMethod*
mini_method_to_shared (MonoMethod *method); // null if not shared
Expand Down
88 changes: 27 additions & 61 deletions src/mono/mono/mini/simd-intrinsics.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#include <mono/metadata/reflection-internals.h>
#include <mono/utils/mono-hwcap.h>

#if defined (MONO_ARCH_SIMD_INTRINSICS)

#if defined(DISABLE_JIT)

void
Expand Down Expand Up @@ -1100,8 +1098,6 @@ emit_vector_create_elementwise (
return ins;
}

#if defined(TARGET_AMD64) || defined(TARGET_ARM64) || defined(TARGET_WASM)

static int
type_to_xinsert_op (MonoTypeEnum type)
{
Expand Down Expand Up @@ -1425,6 +1421,9 @@ emit_sri_vector (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsi
if (vector_size == 256 || vector_size == 512)
return NULL;

if (!(cfg->opt & MONO_OPT_SIMD))
return NULL;

// FIXME: This limitation could be removed once everything here are supported by mini JIT on arm64
#ifdef TARGET_ARM64
if (!COMPILE_LLVM (cfg)) {
Expand Down Expand Up @@ -2520,6 +2519,9 @@ emit_sri_vector_t (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *f
return ins;
}

if (!(cfg->opt & MONO_OPT_SIMD))
return NULL;

/* Vector256/Vector512 */
if (size == 32 || size == 64)
return NULL;
Expand Down Expand Up @@ -2744,6 +2746,9 @@ emit_vector_2_3_4 (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *f
return NULL;
#endif

if (!(cfg->opt & MONO_OPT_SIMD))
return NULL;

if (cfg->verbose_level > 1) {
char *name = mono_method_full_name (cmethod, TRUE);
printf (" SIMD intrinsic %s\n", name);
Expand Down Expand Up @@ -3089,8 +3094,6 @@ emit_vector_2_3_4 (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *f
return NULL;
}

#endif // defined(TARGET_AMD64) || defined(TARGET_ARM64) || defined(TARGET_WASM)

#ifdef TARGET_ARM64

static SimdIntrinsic armbase_methods [] = {
Expand Down Expand Up @@ -5608,9 +5611,11 @@ emit_simd_intrinsics (const char *class_ns, const char *class_name, MonoCompile
{
MonoInst *ins;

ins = arch_emit_simd_intrinsics (class_ns, class_name, cfg, cmethod, fsig, args);
if (ins)
return ins;
if (cfg->opt & MONO_OPT_SIMD) {
ins = arch_emit_simd_intrinsics (class_ns, class_name, cfg, cmethod, fsig, args);
if (ins)
return ins;
}

if (!strcmp (class_ns, "System.Runtime.Intrinsics")) {
if (!strcmp (class_name, "Vector64") || !strcmp (class_name, "Vector128") || !strcmp (class_name, "Vector256") || !strcmp (class_name, "Vector512"))
Expand Down Expand Up @@ -5749,8 +5754,17 @@ mono_simd_decompose_intrinsic (MonoCompile *cfg, MonoBasicBlock *bb, MonoInst *i
}
}

#else

void
mono_simd_decompose_intrinsic (MonoCompile *cfg, MonoBasicBlock *bb, MonoInst *ins)
{
}

#endif /*defined(TARGET_WIN32) && defined(TARGET_AMD64)*/

gboolean
mono_simd_unsupported_aggressive_inline_intrinsic_type (MonoMethod *cmethod)
mono_simd_unsupported_aggressive_inline_intrinsic_type (MonoCompile *cfg, MonoMethod *cmethod)
{
/*
* If a method has been marked with aggressive inlining, check if we support
Expand All @@ -5761,66 +5775,18 @@ mono_simd_unsupported_aggressive_inline_intrinsic_type (MonoMethod *cmethod)
if (!strcmp (m_class_get_name_space (cmethod->klass), "System.Runtime.Intrinsics")) {
if (!strncmp(m_class_get_name (cmethod->klass), "Vector", 6)) {
const char *vector_type = m_class_get_name (cmethod->klass) + 6;
if (!strcmp(vector_type, "256`1") || !strcmp(vector_type, "512`1"))
if (!strcmp(vector_type, "256`1") || !strcmp(vector_type, "512`1") || !strcmp(vector_type, "256") || !strcmp(vector_type, "512"))
return TRUE;
if (!(cfg->opt & MONO_OPT_SIMD) && (!strcmp (vector_type, "128`1") || !strcmp (vector_type, "128") || !strcmp (vector_type, "64`1") || !strcmp (vector_type, "64")))
return TRUE;
}
}
return FALSE;
}
#else
void
mono_simd_decompose_intrinsic (MonoCompile *cfg, MonoBasicBlock *bb, MonoInst *ins)
{
}

gboolean
mono_simd_unsupported_aggressive_inline_intrinsic_type (MonoMethod* cmethod)
{
return FALSE;
}

#endif /*defined(TARGET_WIN32) && defined(TARGET_AMD64)*/

#endif /* DISABLE_JIT */

#else /* MONO_ARCH_SIMD_INTRINSICS */

void
mono_simd_intrinsics_init (void)
{
}

MonoInst*
mono_emit_simd_field_load (MonoCompile *cfg, MonoClassField *field, MonoInst *addr)
{
return NULL;
}

MonoInst*
mono_emit_simd_intrinsics (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args)
{
return NULL;
}

MonoInst*
mono_emit_common_intrinsics (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args)
{
return NULL;
}

void
mono_simd_decompose_intrinsic (MonoCompile *cfg, MonoBasicBlock *bb, MonoInst *ins)
{
}

gboolean
mono_simd_unsupported_aggressive_inline_intrinsic_type (MonoMethod* cmethod)
{
return FALSE;
}

#endif /* MONO_ARCH_SIMD_INTRINSICS */

#if defined(TARGET_AMD64)
void
ves_icall_System_Runtime_Intrinsics_X86_X86Base___cpuidex (int abcd[4], int function_id, int subfunction_id)
Expand Down
Loading