[llvm] do not emit safe points for simple methods (mono/mono#13887)
authorEgor Bogatov <egorbo@gmail.com>
Mon, 8 Apr 2019 08:53:52 +0000 (11:53 +0300)
committerBernhard Urban <bernhard.urban@xamarin.com>
Mon, 8 Apr 2019 08:53:52 +0000 (10:53 +0200)
* 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

index 52ae5f6..eeb0ee2 100644 (file)
@@ -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);