From f74154f5cca3031746112ce5621365393d4ce824 Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Mon, 8 Apr 2019 11:53:52 +0300 Subject: [PATCH] [llvm] do not emit safe points for simple methods (mono/mono#13887) * do not emit sp on method entry for simple methods * do not emit sp on method entry for simple methods * address feedback Commit migrated from https://github.com/mono/mono/commit/b49e72950e31975cdd3f0062e112b87ebf12d9d9 --- src/mono/mono/mini/mini-llvm.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/mono/mono/mini/mini-llvm.c b/src/mono/mono/mini/mini-llvm.c index 52ae5f6..eeb0ee2 100644 --- a/src/mono/mono/mini/mini-llvm.c +++ b/src/mono/mono/mini/mini-llvm.c @@ -7610,7 +7610,21 @@ emit_method_inner (EmitContext *ctx) if (!cfg->llvm_only) LLVMSetFunctionCallConv (method, LLVMMono1CallConv); - if (!cfg->llvm_only && cfg->compile_aot && mono_threads_are_safepoints_enabled ()) + + /* 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; + if (!requires_safepoint) { + 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; + } + } + } + + if (!cfg->llvm_only && cfg->compile_aot && mono_threads_are_safepoints_enabled () && requires_safepoint) LLVMSetGC (method, "mono"); LLVMSetLinkage (method, LLVMPrivateLinkage); -- 2.7.4