Author: zoltan
Date: 2006-10-05 05:07:31 -0400 (Thu, 05 Oct 2006)
New Revision: 66279
Modified:
trunk/mono/mono/mini/ChangeLog
trunk/mono/mono/mini/iltests.il
trunk/mono/mono/mini/mini-x86.c
trunk/mono/mono/mini/mini.c
Log:
2006-10-05 Zoltan Varga <[EMAIL PROTECTED]>
* mini-x86.c (emit_load_volatile_arguments): New function to handle
arguments of
tail calls as on other platforms.
* mini.c (mono_method_to_ir): Fix a few tailcall problems. Fixes #79557.
* iltests.il: Add a few tailcall tests.
Modified: trunk/mono/mono/mini/ChangeLog
===================================================================
--- trunk/mono/mono/mini/ChangeLog 2006-10-05 08:39:11 UTC (rev 66278)
+++ trunk/mono/mono/mini/ChangeLog 2006-10-05 09:07:31 UTC (rev 66279)
@@ -1,4 +1,12 @@
+2006-10-05 Zoltan Varga <[EMAIL PROTECTED]>
+ * mini-x86.c (emit_load_volatile_arguments): New function to handle
arguments of
+ tail calls as on other platforms.
+
+ * mini.c (mono_method_to_ir): Fix a few tailcall problems. Fixes #79557.
+
+ * iltests.il: Add a few tailcall tests.
+
Tue Oct 3 16:33:08 CEST 2006 Paolo Molaro <[EMAIL PROTECTED]>
* driver.c: fix loop for old compilers (bug #79521).
Modified: trunk/mono/mono/mini/iltests.il
===================================================================
--- trunk/mono/mono/mini/iltests.il 2006-10-05 08:39:11 UTC (rev 66278)
+++ trunk/mono/mono/mini/iltests.il 2006-10-05 09:07:31 UTC (rev 66279)
@@ -510,6 +510,53 @@
ret
}
+ .method static public int32 tail3 (int32 i, int32 j) il managed {
+ ldarg.0
+ ldarg.1
+ add
+ ret
+ }
+
+ .method static public int32 tail4 (int32 i, int32 j) il managed {
+ .maxstack 16
+ .locals init (
+ int32 k)
+
+ // Test arg0 allocated to a register
+ ldarg.0
+ ldarg.0
+ ldarg.0
+ ldarg.0
+ add
+ add
+ add
+ starg 0
+
+ // Test switched up argument variables as the actual arguments
+ ldarg.1
+ ldarg.0
+ tail.
+ call int32 Tests::tail3 (int32, int32)
+ ret
+ }
+
+ .method static public int32 test_24_tail_calls2 () il managed {
+ .maxstack 16
+ .locals init (
+ int32 i,
+ int32 j)
+
+ ldc.i4.4
+ stloc.0
+ ldc.i4.8
+ stloc.1
+
+ ldloc.0
+ ldloc.1
+ call int32 Tests::tail4 (int32, int32)
+ ret
+ }
+
.method public static int32 test_5_jmp () cil managed {
jmp int32 Tests::jmp2 ()
ldc.i4.0
Modified: trunk/mono/mono/mini/mini-x86.c
===================================================================
--- trunk/mono/mono/mini/mini-x86.c 2006-10-05 08:39:11 UTC (rev 66278)
+++ trunk/mono/mono/mini/mini-x86.c 2006-10-05 09:07:31 UTC (rev 66279)
@@ -1702,6 +1702,55 @@
return code;
}
+/*
+ * emit_load_volatile_arguments:
+ *
+ * Load volatile arguments from the stack to the original input registers.
+ * Required before a tail call.
+ */
+static guint8*
+emit_load_volatile_arguments (MonoCompile *cfg, guint8 *code)
+{
+ MonoMethod *method = cfg->method;
+ MonoMethodSignature *sig;
+ MonoInst *inst;
+ CallInfo *cinfo;
+ guint32 i;
+
+ /* FIXME: Generate intermediate code instead */
+
+ sig = mono_method_signature (method);
+
+ cinfo = get_call_info (sig, FALSE);
+
+ /* This is the opposite of the code in emit_prolog */
+
+ for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
+ ArgInfo *ainfo = cinfo->args + i;
+ MonoType *arg_type;
+ inst = cfg->varinfo [i];
+
+ if (sig->hasthis && (i == 0))
+ arg_type = &mono_defaults.object_class->byval_arg;
+ else
+ arg_type = sig->params [i - sig->hasthis];
+
+ /*
+ * On x86, the arguments are either in their original stack
locations, or in
+ * global regs.
+ */
+ if (inst->opcode == OP_REGVAR) {
+ g_assert (ainfo->storage == ArgOnStack);
+
+ x86_mov_membase_reg (code, X86_EBP, inst->inst_offset,
inst->dreg, 4);
+ }
+ }
+
+ g_free (cinfo);
+
+ return code;
+}
+
#define REAL_PRINT_REG(text,reg) \
mono_assert (reg >= 0); \
x86_push_reg (code, X86_EAX); \
@@ -2250,6 +2299,8 @@
g_assert (!cfg->method->save_lmf);
+ code = emit_load_volatile_arguments (cfg, code);
+
if (cfg->used_int_regs & (1 << X86_EBX))
pos -= 4;
if (cfg->used_int_regs & (1 << X86_EDI))
Modified: trunk/mono/mono/mini/mini.c
===================================================================
--- trunk/mono/mono/mini/mini.c 2006-10-05 08:39:11 UTC (rev 66278)
+++ trunk/mono/mono/mini/mini.c 2006-10-05 09:07:31 UTC (rev 66279)
@@ -4544,14 +4544,25 @@
/* Prevent inlining of methods with tail calls
(the call stack would be altered) */
INLINE_FAILURE;
/* FIXME: This assumes the two methods has the
same number and type of arguments */
+ /*
+ * We implement tail calls by storing the
actual arguments into the
+ * argument variables, then emitting a CEE_JMP.
Since the actual arguments
+ * can refer to the arg variables, we have to
spill them.
+ */
+ handle_loaded_temps (cfg, bblock, sp, sp + n);
for (i = 0; i < n; ++i) {
+ /* Prevent argument from being register
allocated */
+ arg_array [i]->flags |=
MONO_INST_VOLATILE;
+
/* Check if argument is the same */
+ /*
+ * FIXME: This loses liveness info, so
it can only be done if the
+ * argument is not register allocated.
+ */
NEW_ARGLOAD (cfg, ins, i);
if ((ins->opcode == sp [i]->opcode) &&
(ins->inst_i0 == sp [i]->inst_i0))
continue;
- /* Prevent argument from being register
allocated */
- arg_array [i]->flags |=
MONO_INST_VOLATILE;
NEW_ARGSTORE (cfg, ins, i, sp [i]);
ins->cil_code = ip;
if (ins->opcode == CEE_STOBJ) {
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches