diff options
author | Bernhard Urban <bernhard.urban@xamarin.com> | 2018-11-06 15:25:38 +0300 |
---|---|---|
committer | monojenkins <jo.shields+jenkins@xamarin.com> | 2018-11-06 15:25:38 +0300 |
commit | c200ccbb6265d6564cf72217b58991874f5148e5 (patch) | |
tree | c8632bcfec363f8feaf0de67f12a360c1316f7ed | |
parent | c8d59d1d1ddc140aec489e7d0e8bd338324fec04 (diff) |
[mini] do not emit safepoints for methods without calls and loops (#11554)
[mini] do not emit safepoints for methods without calls and loops
with this optimization, running Roslyn with mono on
`mono/tests/pinvoke11.cs` compiles:
* 2019 methods without safepoints, and
* 9443 methods with safepoints.
-rw-r--r-- | mono/mini/method-to-ir.c | 2 | ||||
-rw-r--r-- | mono/mini/mini.c | 15 | ||||
-rw-r--r-- | mono/mini/mini.h | 1 |
3 files changed, 16 insertions, 2 deletions
diff --git a/mono/mini/method-to-ir.c b/mono/mini/method-to-ir.c index 2bcbbb099c8..00ca3ff350d 100644 --- a/mono/mini/method-to-ir.c +++ b/mono/mini/method-to-ir.c @@ -2314,6 +2314,8 @@ mono_emit_call_args (MonoCompile *cfg, MonoMethodSignature *sig, MonoType *sig_ret; MonoCallInst *call; + cfg->has_calls = TRUE; + if (tailcall && cfg->llvm_only) { // FIXME tailcall should not be changed this late. // FIXME It really should not be changed due to llvm_only. diff --git a/mono/mini/mini.c b/mono/mini/mini.c index 9db9544e0dd..a31eb364d06 100644 --- a/mono/mini/mini.c +++ b/mono/mini/mini.c @@ -2947,11 +2947,22 @@ mono_insert_safepoints (MonoCompile *cfg) if (cfg->verbose_level > 2) mono_print_code (cfg, "BEFORE SAFEPOINTS"); - for (bb = cfg->bb_entry; bb; bb = bb->next_bb) { - if (bb->loop_body_start || bb == cfg->bb_entry || bb->flags & BB_EXCEPTION_HANDLER) + /* if the method doesn't contain + * (1) a call (so it's a leaf method) + * (2) and no loops + * we can skip the GC safepoint on method entry. */ + gboolean requires_safepoint = cfg->has_calls; + + for (bb = cfg->bb_entry->next_bb; bb; bb = bb->next_bb) { + if (bb->loop_body_start || bb->flags & BB_EXCEPTION_HANDLER) { + requires_safepoint = TRUE; mono_create_gc_safepoint (cfg, bb); + } } + if (requires_safepoint) + mono_create_gc_safepoint (cfg, cfg->bb_entry); + if (cfg->verbose_level > 2) mono_print_code (cfg, "AFTER SAFEPOINTS"); diff --git a/mono/mini/mini.h b/mono/mini/mini.h index 37ab05ff588..3ac749cd760 100644 --- a/mono/mini/mini.h +++ b/mono/mini/mini.h @@ -1369,6 +1369,7 @@ typedef struct { guint compute_gc_maps : 1; guint soft_breakpoints : 1; guint arch_eh_jit_info : 1; + guint has_calls : 1; guint has_emulated_ops : 1; guint has_indirection : 1; guint has_atomic_add_i4 : 1; |