diff options
author | Johan Lorensson <lateralusx.github@gmail.com> | 2020-12-11 11:06:51 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-11 11:06:51 +0300 |
commit | 6968cb28c3fc2f9be6e164f9891ae0f1d4a9e896 (patch) | |
tree | 902324b050ca71ff102a571875078890cfa75828 | |
parent | 685e0eeba855446e08a8e3fc8a500ab9c573342d (diff) |
Add support for global aggressive-linining optimization. (#20641)
* Add support for global aggressive-linining optimization.
Currently we do support aggressive inlining per method using attributes.
This commit adds a new global mono optimization flag that does similar
thing, but whiout the need to annotate methods. There is still one big
difference and that is the effect of cost. The new global optimization
does not override cost evaluation, so if a method is to expensive to
inline with regards to inline limit, it won't be inlined. In order to
get the full "forced" inlining. method attributes should still be used.
This new optimization is not default and needs to be enabled using:
--optimize=aggressive-inlining
* Keep default inline limit on none netcore builds.
-rw-r--r-- | mono/mini/method-to-ir.c | 17 | ||||
-rw-r--r-- | mono/mini/mini-runtime.c | 3 | ||||
-rw-r--r-- | mono/mini/optflags-def.h | 1 |
3 files changed, 12 insertions, 9 deletions
diff --git a/mono/mini/method-to-ir.c b/mono/mini/method-to-ir.c index d738e7d7466..3e383722bcf 100644 --- a/mono/mini/method-to-ir.c +++ b/mono/mini/method-to-ir.c @@ -97,7 +97,12 @@ * while the jit only sees one method, so we have to inline things ourselves. */ /* Used by LLVM AOT */ +#ifdef ENABLE_NETCORE #define LLVM_AOT_INLINE_LENGTH_LIMIT 30 +#else +#define LLVM_AOT_INLINE_LENGTH_LIMIT INLINE_LENGTH_LIMIT +#endif + /* Used to LLVM JIT */ #define LLVM_JIT_INLINE_LENGTH_LIMIT 100 @@ -3931,7 +3936,6 @@ mono_method_check_inlining (MonoCompile *cfg, MonoMethod *method) inline_limit_inited = TRUE; } -#ifdef ENABLE_NETCORE if (COMPILE_LLVM (cfg)) { if (cfg->compile_aot) limit = llvm_aot_inline_limit; @@ -3940,12 +3944,7 @@ mono_method_check_inlining (MonoCompile *cfg, MonoMethod *method) } else { limit = inline_limit; } -#else - if (COMPILE_LLVM (cfg) && !cfg->compile_aot) - limit = llvm_jit_inline_limit; - else - limit = inline_limit; -#endif + if (header.code_size >= limit && !(method->iflags & METHOD_IMPL_ATTRIBUTE_AGGRESSIVE_INLINING)) return FALSE; @@ -3960,7 +3959,7 @@ mono_method_check_inlining (MonoCompile *cfg, MonoMethod *method) if (!(cfg->opt & MONO_OPT_SHARED)) { /* The AggressiveInlining hint is a good excuse to force that cctor to run. */ - if (method->iflags & METHOD_IMPL_ATTRIBUTE_AGGRESSIVE_INLINING) { + if ((cfg->opt & MONO_OPT_AGGRESSIVE_INLINING) || method->iflags & METHOD_IMPL_ATTRIBUTE_AGGRESSIVE_INLINING) { if (m_class_has_cctor (method->klass)) { ERROR_DECL (error); vtable = mono_class_vtable_checked (cfg->domain, method->klass, error); @@ -7947,7 +7946,7 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b } /* Common call */ - if (!(method->iflags & METHOD_IMPL_ATTRIBUTE_AGGRESSIVE_INLINING) && !(cmethod->iflags & METHOD_IMPL_ATTRIBUTE_AGGRESSIVE_INLINING)) + if (!(cfg->opt & MONO_OPT_AGGRESSIVE_INLINING) && !(method->iflags & METHOD_IMPL_ATTRIBUTE_AGGRESSIVE_INLINING) && !(cmethod->iflags & METHOD_IMPL_ATTRIBUTE_AGGRESSIVE_INLINING)) INLINE_FAILURE ("call"); common_call = TRUE; diff --git a/mono/mini/mini-runtime.c b/mono/mini/mini-runtime.c index 695f24bebf4..cc75653bdd8 100644 --- a/mono/mini/mini-runtime.c +++ b/mono/mini/mini-runtime.c @@ -5124,6 +5124,9 @@ mono_disable_optimizations (guint32 opts) void mono_set_optimizations (guint32 opts) { + if (opts & MONO_OPT_AGGRESSIVE_INLINING) + opts |= MONO_OPT_INLINE; + default_opt = opts; default_opt_set = TRUE; #ifdef MONO_ARCH_GSHAREDVT_SUPPORTED diff --git a/mono/mini/optflags-def.h b/mono/mini/optflags-def.h index 481abfee0c2..3f28b071765 100644 --- a/mono/mini/optflags-def.h +++ b/mono/mini/optflags-def.h @@ -29,3 +29,4 @@ OPTFLAG (GSHARED, 25, "gshared", "Generic Sharing") OPTFLAG(SIMD ,26, "simd", "Simd intrinsics") OPTFLAG(UNSAFE ,27, "unsafe", "Remove bound checks and perform other dangerous changes") OPTFLAG(ALIAS_ANALYSIS ,28, "alias-analysis", "Alias analysis of locals") +OPTFLAG (AGGRESSIVE_INLINING, 29, "aggressive-inlining", "Aggressive Inlining") |