Update Haiku support (#15674)
[mono-project.git] / mono / tests / tailcall-rgctxb-small.il
blob42dbf295a58fff5d66c3597ea8dc50dc0dae7537
1 /*
2 Author:
3     Jay Krell (jaykrell@microsoft.com)
5 Copyright 2018 Microsoft
6 Licensed under the MIT license. See LICENSE file in the project root for full license information.
8 http://www.mono-project.com/docs/advanced/runtime/docs/generic-sharing/
9 1. Non-generic non-static methods of reference types have access to the
10    RGCTX via the “this” argument (this->vtable->rgctx).
11 2. a. Non-generic static methods of reference types and b. non-generic methods
12    of value types need to be passed a pointer to the caller’s class’s VTable in the MONO_ARCH_RGCTX_REG register.
13 3. Generic methods need to be passed a pointer to the MRGCTX in the MONO_ARCH_RGCTX_REG register
15 Test case 2b, with a small type.
17 using System;
18 using System.Runtime.CompilerServices;
19 using static System.Runtime.CompilerServices.MethodImplOptions;
21 unsafe struct A<T>
23     void f3 ()
24     {
25         a = 1;
26     }
27     public int a;
29     [MethodImpl (NoInlining)]
30     static int check (long stack1, long stack2)
31     {
32         return (stack1 == stack2) ? 0 : 1;
33     }
35     [MethodImpl (NoInlining)]
36     public int Method1 (int counter, long initial_stack, long current_stack)
37     {
38         int local;
39         object a = new T[101];
40         if (counter > 0)
41             return Method2 (counter - 1, initial_stack, (long)&local);
42         return check ((long)&local, current_stack);
43     }
45     [MethodImpl (NoInlining)]
46     public int Method2 (int counter, long initial_stack, long current_stack)
47     {
48         int local;
49         object a = new T[101];
50         if (counter > 0)
51             return Method1 (counter - 1, initial_stack, (long)&local);
52         return check ((long)&local, current_stack);
53     }
56 unsafe class B
58     [MethodImpl (NoInlining)]
59     public static void Main()
60     {
61         int stack;
62         Environment.Exit(new A<int>().Method1 (100, (long)&stack, 0));
63     }
67 .assembly extern mscorlib { }
69 .assembly 'tailcall-rgctxb' { }
71 .class A`1<T>
73 // Remove this change the test a lot and make it pass.
74 // It is ok in this case because the ValueType is small.
75 extends [mscorlib]System.ValueType
78 .method static int32 check (int64 stack1, int64 stack2) noinlining
80         ldarg.0
81         ldarg.1
82         beq.s IL_0006
84         ldc.i4.1
85         ret
87 IL_0006:
88         ldc.i4.0
89         ret
92 .method instance int32 Method1 (int32 counter, int64 initial_stack, int64 current_stack) noinlining
94         .locals init (int32 V_0)
96         ldarg.1
97         ldc.i4.0
98         ble.s IL_001b
100         ldarg.0
101         ldarg.1
102         ldc.i4.1
103         sub
104         ldarg.2
105         ldloca.s V_0
106         conv.u
107         conv.u8
108         tail. call instance int32 valuetype A`1<!T>::Method2 (int32, int64, int64)
109         ret
111 IL_001b:
112         ldloca.s V_0
113         conv.u
114         conv.u8
115         ldarg.3
116         tail. call int32 valuetype A`1<!T>::check (int64, int64)
117         ret
120 .method instance int32 Method2 (int32 counter, int64 initial_stack, int64 current_stack) noinlining
122         .locals init (int32 V_0)
123         ldarg.1
124         ldc.i4.0
125         ble.s IL_001b
127         ldarg.0
128         ldarg.1
129         ldc.i4.1
130         sub
131         ldarg.2
132         ldloca.s V_0
133         conv.u
134         conv.u8
135         tail. call instance int32 valuetype A`1<!T>::Method1 (int32, int64, int64)
136         ret
138 IL_001b:
139         ldloca.s V_0
140         conv.u
141         conv.u8
142         ldarg.3
143         tail. call int32 valuetype A`1<!T>::check (int64, int64)
144         ret
148 .class B extends [mscorlib]System.Object
151 .method static int32 Main() noinlining
153         .entrypoint
154         .locals init (int32 V_0, valuetype A`1<int32> V_1)
155         ldloca.s V_1
156         initobj valuetype A`1<int32>
157         ldloc.1
158         stloc.1
159         ldloca.s V_1
160         ldc.i4.s 100
161         ldloca.s V_0
162         conv.u
163         conv.u8
164         ldc.i4.0
165         conv.i8
166         tail. call instance int32 valuetype A`1<int32>::Method1 (int32, int64, int64)
167         ret
170 .method instance void .ctor()
172         ldarg.0
173         tail. call instance void [mscorlib]System.Object::.ctor ()
174         ret