[mono/mono] 90e0dbcc: [jit] Clean up the tail call code a bit.

"Zoltan Varga ([email protected])" <[email protected]> Sat, 2 Nov 2013 21:15:15 +0000
Newsgroups gmane.comp.gnome.mono.patches
Message-ID <000001421aab7d27-b286b05b-eb56-4be8-9186-9e2409e03572-000000@email.amazonses.com>
   Branch: refs/heads/master
     Home: https://github.com/mono/mono
  Compare: https://github.com/mono/mono/compare/56fa47629fd8...90e0dbcc1731

   Commit: 90e0dbcc1731fc15d55d5319a553915f0a6916fd
   Author: Zoltan Varga <[email protected]> (vargaz)
     Date: 2013-11-02 21:14:18 GMT
      URL: https://github.com/mono/mono/commit/90e0dbcc1731fc15d55d5319a553915f0a6916fd

[jit] Clean up the tail call code a bit.

Changed paths:
  M mono/mini/method-to-ir.c
  M mono/mini/mini-amd64.c
  M mono/mini/mini-amd64.h
  M mono/mini/mini-ppc.c
  M mono/mini/mini-ppc.h
  M mono/mini/mini-x86.c
  M mono/mini/mini-x86.h
  M mono/mini/mini.h

Modified: mono/mini/method-to-ir.c
===================================================================
@@ -6351,13 +6351,13 @@ gboolean check_linkdemand (MonoCompile *cfg, MonoMethod *caller, MonoMethod *cal
 }
 
 static gboolean
-is_supported_tail_call (MonoCompile *cfg, MonoMethod *method, MonoMethod *cmethod, MonoMethodSignature *fsig)
+is_supported_tail_call (MonoCompile *cfg, MonoMethod *method, MonoMethod *cmethod, MonoMethodSignature *fsig, int call_opcode)
 {
 	gboolean supported_tail_call;
 	int i;
 
-#ifdef MONO_ARCH_USE_OP_TAIL_CALL
-	supported_tail_call = MONO_ARCH_USE_OP_TAIL_CALL (mono_method_signature (method), mono_method_signature (cmethod));
+#ifdef MONO_ARCH_HAVE_OP_TAIL_CALL
+	supported_tail_call = mono_arch_tail_call_supported (mono_method_signature (method), mono_method_signature (cmethod));
 #else
 	supported_tail_call = mono_metadata_signature_equal (mono_method_signature (method), mono_method_signature (cmethod)) && !MONO_TYPE_ISSTRUCT (mono_method_signature (cmethod)->ret);
 #endif
@@ -6376,6 +6376,8 @@ gboolean check_linkdemand (MonoCompile *cfg, MonoMethod *caller, MonoMethod *cal
 		supported_tail_call = FALSE;
 	if (cmethod->wrapper_type && cmethod->wrapper_type != MONO_WRAPPER_DYNAMIC_METHOD)
 		supported_tail_call = FALSE;
+	if (call_opcode != CEE_CALL)
+		supported_tail_call = FALSE;
 
 	/* Debugging support */
 #if 0
@@ -7437,8 +7439,7 @@ gboolean check_linkdemand (MonoCompile *cfg, MonoMethod *caller, MonoMethod *cal
 			if (mono_security_cas_enabled ())
 				CHECK_CFG_EXCEPTION;
 
-#ifdef MONO_ARCH_USE_OP_TAIL_CALL
-			{
+			if (ARCH_HAVE_OP_TAIL_CALL) {
 				MonoMethodSignature *fsig = mono_method_signature (cmethod);
 				int i, n;
 
@@ -7456,17 +7457,16 @@ gboolean check_linkdemand (MonoCompile *cfg, MonoMethod *caller, MonoMethod *cal
 
 				mono_arch_emit_call (cfg, call);
 				MONO_ADD_INS (bblock, (MonoInst*)call);
-			}
-#else
-			for (i = 0; i < num_args; ++i)
-				/* Prevent arguments from being optimized away */
-				arg_array [i]->flags |= MONO_INST_VOLATILE;
+			} else {
+				for (i = 0; i < num_args; ++i)
+					/* Prevent arguments from being optimized away */
+					arg_array [i]->flags |= MONO_INST_VOLATILE;
 
-			MONO_INST_NEW_CALL (cfg, call, OP_JMP);
-			ins = (MonoInst*)call;
-			ins->inst_p0 = cmethod;
-			MONO_ADD_INS (bblock, ins);
-#endif
+				MONO_INST_NEW_CALL (cfg, call, OP_JMP);
+				ins = (MonoInst*)call;
+				ins->inst_p0 = cmethod;
+				MONO_ADD_INS (bblock, ins);
+			}
 
 			ip += 5;
 			start_new_bblock = 1;
@@ -8231,12 +8231,8 @@ gboolean check_linkdemand (MonoCompile *cfg, MonoMethod *caller, MonoMethod *cal
 			/* FIXME: runtime generic context pointer for jumps? */
 			/* FIXME: handle this for generic sharing eventually */
 			if (cmethod && (ins_flag & MONO_INST_TAILCALL) &&
-				!vtable_arg && !cfg->generic_sharing_context && is_supported_tail_call (cfg, method, cmethod, fsig))
+				!vtable_arg && !cfg->generic_sharing_context && is_supported_tail_call (cfg, method, cmethod, fsig, call_opcode))
 				supported_tail_call = TRUE;
-			if (supported_tail_call) {
-				if (call_opcode != CEE_CALL)
-					supported_tail_call = FALSE;
-			}
 
 			if (supported_tail_call) {
 				MonoCallInst *call;
@@ -8246,7 +8242,7 @@ gboolean check_linkdemand (MonoCompile *cfg, MonoMethod *caller, MonoMethod *cal
 
 				//printf ("HIT: %s -> %s\n", mono_method_full_name (cfg->method, TRUE), mono_method_full_name (cmethod, TRUE));
 
-				if (ARCH_USE_OP_TAIL_CALL) {
+				if (ARCH_HAVE_OP_TAIL_CALL) {
 					/* Handle tail calls similarly to normal calls */
 					tail_call = TRUE;
 				} else {

Modified: mono/mini/mini-amd64.c
===================================================================
@@ -1204,7 +1204,7 @@
 }
 
 gboolean
-mono_amd64_tail_call_supported (MonoMethodSignature *caller_sig, MonoMethodSignature *callee_sig)
+mono_arch_tail_call_supported (MonoMethodSignature *caller_sig, MonoMethodSignature *callee_sig)
 {
 	CallInfo *c1, *c2;
 	gboolean res;

Modified: mono/mini/mini-amd64.h
===================================================================
@@ -396,16 +396,12 @@ struct MonoLMF {
 #define MONO_ARCH_HAVE_CONTEXT_SET_INT_REG 1
 #define MONO_ARCH_HAVE_SETUP_ASYNC_CALLBACK 1
 #define MONO_ARCH_HAVE_CREATE_LLVM_NATIVE_THUNK 1
+#define MONO_ARCH_HAVE_OP_TAIL_CALL 1
 
 #if defined(TARGET_OSX) || defined(__linux__)
 #define MONO_ARCH_HAVE_TLS_GET_REG 1
 #endif
 
-gboolean
-mono_amd64_tail_call_supported (MonoMethodSignature *caller_sig, MonoMethodSignature *callee_sig) MONO_INTERNAL;
-
-#define MONO_ARCH_USE_OP_TAIL_CALL(caller_sig, callee_sig) mono_amd64_tail_call_supported (caller_sig, callee_sig)
-
 /* Used for optimization, not complete */
 #define MONO_ARCH_IS_OP_MEMBASE(opcode) ((opcode) == OP_X86_PUSH_MEMBASE)
 

Modified: mono/mini/mini-ppc.c
===================================================================
@@ -1255,7 +1255,7 @@ enum {
 }
 
 gboolean
-mono_ppc_tail_call_supported (MonoMethodSignature *caller_sig, MonoMethodSignature *callee_sig)
+mono_arch_tail_call_supported (MonoMethodSignature *caller_sig, MonoMethodSignature *callee_sig)
 {
 	CallInfo *c1, *c2;
 	gboolean res;

Modified: mono/mini/mini-ppc.h
===================================================================
@@ -195,6 +195,7 @@ struct MonoLMF {
 #define MONO_ARCH_SOFT_DEBUG_SUPPORTED 1
 #endif
 #define MONO_ARCH_THIS_AS_FIRST_ARG 1
+#define MONO_ARCH_HAVE_OP_TAIL_CALL 1
 
 #define PPC_NUM_REG_ARGS (PPC_LAST_ARG_REG-PPC_FIRST_ARG_REG+1)
 #define PPC_NUM_REG_FPARGS (PPC_LAST_FPARG_REG-PPC_FIRST_FPARG_REG+1)
@@ -304,8 +305,6 @@ struct MonoLMF {
 gboolean
 mono_ppc_tail_call_supported (MonoMethodSignature *caller_sig, MonoMethodSignature *callee_sig) MONO_INTERNAL;
 
-#define MONO_ARCH_USE_OP_TAIL_CALL(caller_sig, callee_sig) mono_ppc_tail_call_supported (caller_sig, callee_sig)
-
 void
 mono_ppc_patch (guchar *code, const guchar *target) MONO_INTERNAL;
 

Modified: mono/mini/mini-x86.c
===================================================================
@@ -704,7 +704,7 @@ static const guint32 *callconv_param_regs(MonoMethodSignature *sig)
 }
 
 gboolean
-mono_x86_tail_call_supported (MonoMethodSignature *caller_sig, MonoMethodSignature *callee_sig)
+mono_arch_tail_call_supported (MonoMethodSignature *caller_sig, MonoMethodSignature *callee_sig)
 {
 	MonoType *callee_ret;
 	CallInfo *c1, *c2;

Modified: mono/mini/mini-x86.h
===================================================================
@@ -262,16 +262,12 @@ struct MonoLMF {
 #define MONO_ARCH_HAVE_CONTEXT_SET_INT_REG 1
 #define MONO_ARCH_HAVE_SETUP_ASYNC_CALLBACK 1
 #define MONO_ARCH_GSHAREDVT_SUPPORTED 1
+#define MONO_ARCH_HAVE_OP_TAIL_CALL 1
 
 #ifdef TARGET_OSX
 #define MONO_ARCH_HAVE_TLS_GET_REG 1
 #endif
 
-gboolean
-mono_x86_tail_call_supported (MonoMethodSignature *caller_sig, MonoMethodSignature *callee_sig) MONO_INTERNAL;
-
-#define MONO_ARCH_USE_OP_TAIL_CALL(caller_sig, callee_sig) mono_x86_tail_call_supported (caller_sig, callee_sig)
-
 /* Used for optimization, not complete */
 #define MONO_ARCH_IS_OP_MEMBASE(opcode) ((opcode) == OP_X86_PUSH_MEMBASE)
 

Modified: mono/mini/mini.h
===================================================================
@@ -2288,6 +2288,7 @@ int               mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoB
 gpointer  mono_arch_get_gsharedvt_trampoline    (MonoTrampInfo **info, gboolean aot) MONO_INTERNAL;
 gpointer  mono_arch_get_gsharedvt_call_info     (gpointer addr, MonoMethodSignature *normal_sig, MonoMethodSignature *gsharedvt_sig, MonoGenericSharingContext *gsctx, gboolean gsharedvt_in, gint32 vcall_offset, gboolean calli) MONO_INTERNAL;
 gboolean  mono_arch_opcode_needs_emulation      (MonoCompile *cfg, int opcode) MONO_INTERNAL;
+gboolean  mono_arch_tail_call_supported         (MonoMethodSignature *caller_sig, MonoMethodSignature *callee_sig) MONO_INTERNAL;
 
 #ifdef MONO_ARCH_SOFT_FLOAT_FALLBACK
 gboolean  mono_arch_is_soft_float               (void) MONO_INTERNAL;
@@ -2784,10 +2785,10 @@ enum {
 #define ARCH_HAVE_DELEGATE_TRAMPOLINES 0
 #endif
 
-#ifdef MONO_ARCH_USE_OP_TAIL_CALL
-#define ARCH_USE_OP_TAIL_CALL 1
+#ifdef MONO_ARCH_HAVE_OP_TAIL_CALL
+#define ARCH_HAVE_OP_TAIL_CALL 1
 #else
-#define ARCH_USE_OP_TAIL_CALL 0
+#define ARCH_HAVE_OP_TAIL_CALL 0
 #endif
 
 #ifndef MONO_ARCH_HAVE_TLS_GET


_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches