1; RUN: llc -mtriple=arm64-apple-darwin -mattr=+reserve-x18                             < %s | FileCheck %s
2; RUN: llc -mtriple=arm64-apple-darwin -mattr=+reserve-x18 -fast-isel -fast-isel-abort=1 < %s | FileCheck %s
3;
4; Note: Print verbose stackmaps using -debug-only=stackmaps.
5
6; We are not getting the correct stack alignment when cross compiling for arm64.
7; So specify a datalayout here.
8target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
9
10; CHECK-LABEL:  .section  __LLVM_STACKMAPS,__llvm_stackmaps
11; CHECK-NEXT:  __LLVM_StackMaps:
12; Header
13; CHECK-NEXT:   .byte 3
14; CHECK-NEXT:   .byte 0
15; CHECK-NEXT:   .short 0
16; Num Functions
17; CHECK-NEXT:   .long 11
18; Num LargeConstants
19; CHECK-NEXT:   .long 2
20; Num Callsites
21; CHECK-NEXT:   .long 11
22
23; Functions and stack size
24; CHECK-NEXT:   .quad _constantargs
25; CHECK-NEXT:   .quad 16
26; CHECK-NEXT:   .quad 1
27; CHECK-NEXT:   .quad _osrinline
28; CHECK-NEXT:   .quad 32
29; CHECK-NEXT:   .quad 1
30; CHECK-NEXT:   .quad _osrcold
31; CHECK-NEXT:   .quad 16
32; CHECK-NEXT:   .quad 1
33; CHECK-NEXT:   .quad _propertyRead
34; CHECK-NEXT:   .quad 16
35; CHECK-NEXT:   .quad 1
36; CHECK-NEXT:   .quad _propertyWrite
37; CHECK-NEXT:   .quad 16
38; CHECK-NEXT:   .quad 1
39; CHECK-NEXT:   .quad _jsVoidCall
40; CHECK-NEXT:   .quad 16
41; CHECK-NEXT:   .quad 1
42; CHECK-NEXT:   .quad _jsIntCall
43; CHECK-NEXT:   .quad 16
44; CHECK-NEXT:   .quad 1
45; CHECK-NEXT:   .quad _spilledValue
46; CHECK-NEXT:   .quad 160
47; CHECK-NEXT:   .quad 1
48; CHECK-NEXT:   .quad _spilledStackMapValue
49; CHECK-NEXT:   .quad 128
50; CHECK-NEXT:   .quad 1
51; CHECK-NEXT:   .quad _liveConstant
52; CHECK-NEXT:   .quad 16
53; CHECK-NEXT:   .quad 1
54; CHECK-NEXT:   .quad _clobberLR
55; CHECK-NEXT:   .quad 112
56; CHECK-NEXT:   .quad 1
57
58; Num LargeConstants
59; CHECK-NEXT:   .quad   4294967295
60; CHECK-NEXT:   .quad   4294967296
61
62; Constant arguments
63;
64; CHECK-NEXT:   .quad   1
65; CHECK-NEXT:   .long   L{{.*}}-_constantargs
66; CHECK-NEXT:   .short  0
67; CHECK-NEXT:   .short  4
68; SmallConstant
69; CHECK-NEXT:   .byte   4
70; CHECK-NEXT:   .byte   0
71; CHECK-NEXT:   .short  8
72; CHECK-NEXT:   .short  0
73; CHECK-NEXT:   .short  0
74; CHECK-NEXT:   .long   65535
75; SmallConstant
76; CHECK-NEXT:   .byte   4
77; CHECK-NEXT:   .byte   0
78; CHECK-NEXT:   .short  8
79; CHECK-NEXT:   .short  0
80; CHECK-NEXT:   .short  0
81; CHECK-NEXT:   .long   65536
82; SmallConstant
83; CHECK-NEXT:   .byte   5
84; CHECK-NEXT:   .byte   0
85; CHECK-NEXT:   .short  8
86; CHECK-NEXT:   .short  0
87; CHECK-NEXT:   .short  0
88; CHECK-NEXT:   .long   0
89; LargeConstant at index 0
90; CHECK-NEXT:   .byte   5
91; CHECK-NEXT:   .byte   0
92; CHECK-NEXT:   .short  8
93; CHECK-NEXT:   .short  0
94; CHECK-NEXT:   .short  0
95; CHECK-NEXT:   .long   1
96
97define void @constantargs() {
98entry:
99  %0 = inttoptr i64 244837814094590 to i8*
100  tail call void (i64, i32, i8*, i32, ...) @llvm.experimental.patchpoint.void(i64 1, i32 20, i8* %0, i32 0, i64 65535, i64 65536, i64 4294967295, i64 4294967296)
101  ret void
102}
103
104; Inline OSR Exit
105;
106; CHECK-LABEL:  .long   L{{.*}}-_osrinline
107; CHECK-NEXT:   .short  0
108; CHECK-NEXT:   .short  2
109; CHECK-NEXT:   .byte   1
110; CHECK-NEXT:   .byte   0
111; CHECK-NEXT:   .short  8
112; CHECK-NEXT:   .short  {{[0-9]+}}
113; CHECK-NEXT:   .short  0
114; CHECK-NEXT:   .long   0
115; CHECK-NEXT:   .byte   1
116; CHECK-NEXT:   .byte   0
117; CHECK-NEXT:   .short  8
118; CHECK-NEXT:   .short  {{[0-9]+}}
119; CHECK-NEXT:   .short  0
120; CHECK-NEXT:   .long  0
121define void @osrinline(i64 %a, i64 %b) {
122entry:
123  ; Runtime void->void call.
124  call void inttoptr (i64 244837814094590 to void ()*)()
125  ; Followed by inline OSR patchpoint with 12-byte shadow and 2 live vars.
126  call void (i64, i32, ...) @llvm.experimental.stackmap(i64 3, i32 12, i64 %a, i64 %b)
127  ret void
128}
129
130; Cold OSR Exit
131;
132; 2 live variables in register.
133;
134; CHECK-LABEL:  .long   L{{.*}}-_osrcold
135; CHECK-NEXT:   .short  0
136; CHECK-NEXT:   .short  2
137; CHECK-NEXT:   .byte   1
138; CHECK-NEXT:   .byte   0
139; CHECK-NEXT:   .short  8
140; CHECK-NEXT:   .short  {{[0-9]+}}
141; CHECK-NEXT:   .short  0
142; CHECK-NEXT:   .long   0
143; CHECK-NEXT:   .byte   1
144; CHECK-NEXT:   .byte   0
145; CHECK-NEXT:   .short  8
146; CHECK-NEXT:   .short  {{[0-9]+}}
147; CHECK-NEXT:   .short  0
148; CHECK-NEXT:   .long  0
149define void @osrcold(i64 %a, i64 %b) {
150entry:
151  %test = icmp slt i64 %a, %b
152  br i1 %test, label %ret, label %cold
153cold:
154  ; OSR patchpoint with 12-byte nop-slide and 2 live vars.
155  %thunk = inttoptr i64 244837814094590 to i8*
156  call void (i64, i32, i8*, i32, ...) @llvm.experimental.patchpoint.void(i64 4, i32 20, i8* %thunk, i32 0, i64 %a, i64 %b)
157  unreachable
158ret:
159  ret void
160}
161
162; Property Read
163; CHECK-LABEL:  .long   L{{.*}}-_propertyRead
164; CHECK-NEXT:   .short  0
165; CHECK-NEXT:   .short  0
166;
167; FIXME: There are currently no stackmap entries. After moving to
168; AnyRegCC, we will have entries for the object and return value.
169define i64 @propertyRead(i64* %obj) {
170entry:
171  %resolveRead = inttoptr i64 244837814094590 to i8*
172  %result = call i64 (i64, i32, i8*, i32, ...) @llvm.experimental.patchpoint.i64(i64 5, i32 20, i8* %resolveRead, i32 1, i64* %obj)
173  %add = add i64 %result, 3
174  ret i64 %add
175}
176
177; Property Write
178; CHECK-LABEL:  .long   L{{.*}}-_propertyWrite
179; CHECK-NEXT:   .short  0
180; CHECK-NEXT:   .short  2
181; CHECK-NEXT:   .byte   1
182; CHECK-NEXT:   .byte   0
183; CHECK-NEXT:   .short  8
184; CHECK-NEXT:   .short  {{[0-9]+}}
185; CHECK-NEXT:   .short  0
186; CHECK-NEXT:   .long   0
187; CHECK-NEXT:   .byte   1
188; CHECK-NEXT:   .byte   0
189; CHECK-NEXT:   .short  8
190; CHECK-NEXT:   .short  {{[0-9]+}}
191; CHECK-NEXT:   .short  0
192; CHECK-NEXT:   .long   0
193define void @propertyWrite(i64 %dummy1, i64* %obj, i64 %dummy2, i64 %a) {
194entry:
195  %resolveWrite = inttoptr i64 244837814094590 to i8*
196  call anyregcc void (i64, i32, i8*, i32, ...) @llvm.experimental.patchpoint.void(i64 6, i32 20, i8* %resolveWrite, i32 2, i64* %obj, i64 %a)
197  ret void
198}
199
200; Void JS Call
201;
202; 2 live variables in registers.
203;
204; CHECK-LABEL:  .long   L{{.*}}-_jsVoidCall
205; CHECK-NEXT:   .short  0
206; CHECK-NEXT:   .short  2
207; CHECK-NEXT:   .byte   1
208; CHECK-NEXT:   .byte   0
209; CHECK-NEXT:   .short  8
210; CHECK-NEXT:   .short  {{[0-9]+}}
211; CHECK-NEXT:   .short  0
212; CHECK-NEXT:   .long   0
213; CHECK-NEXT:   .byte   1
214; CHECK-NEXT:   .byte   0
215; CHECK-NEXT:   .short  8
216; CHECK-NEXT:   .short  {{[0-9]+}}
217; CHECK-NEXT:   .short  0
218; CHECK-NEXT:   .long   0
219define void @jsVoidCall(i64 %dummy1, i64* %obj, i64 %arg, i64 %l1, i64 %l2) {
220entry:
221  %resolveCall = inttoptr i64 244837814094590 to i8*
222  call void (i64, i32, i8*, i32, ...) @llvm.experimental.patchpoint.void(i64 7, i32 20, i8* %resolveCall, i32 2, i64* %obj, i64 %arg, i64 %l1, i64 %l2)
223  ret void
224}
225
226; i64 JS Call
227;
228; 2 live variables in registers.
229;
230; CHECK-LABEL:  .long   L{{.*}}-_jsIntCall
231; CHECK-NEXT:   .short  0
232; CHECK-NEXT:   .short  2
233; CHECK-NEXT:   .byte   1
234; CHECK-NEXT:   .byte   0
235; CHECK-NEXT:   .short  8
236; CHECK-NEXT:   .short  {{[0-9]+}}
237; CHECK-NEXT:   .short  0
238; CHECK-NEXT:   .long   0
239; CHECK-NEXT:   .byte   1
240; CHECK-NEXT:   .byte   0
241; CHECK-NEXT:   .short  8
242; CHECK-NEXT:   .short  {{[0-9]+}}
243; CHECK-NEXT:   .short  0
244; CHECK-NEXT:   .long   0
245define i64 @jsIntCall(i64 %dummy1, i64* %obj, i64 %arg, i64 %l1, i64 %l2) {
246entry:
247  %resolveCall = inttoptr i64 244837814094590 to i8*
248  %result = call i64 (i64, i32, i8*, i32, ...) @llvm.experimental.patchpoint.i64(i64 8, i32 20, i8* %resolveCall, i32 2, i64* %obj, i64 %arg, i64 %l1, i64 %l2)
249  %add = add i64 %result, 3
250  ret i64 %add
251}
252
253; Spilled stack map values.
254;
255; Verify 28 stack map entries.
256;
257; CHECK-LABEL:  .long L{{.*}}-_spilledValue
258; CHECK-NEXT:   .short 0
259; CHECK-NEXT:   .short 28
260;
261; Check that at least one is a spilled entry from RBP.
262; Location: Indirect FP + ...
263; CHECK:        .byte 3
264; CHECK-NEXT:   .byte 0
265; CHECK-NEXT:   .short
266; CHECK-NEXT:   .short 29
267; CHECK-NEXT:   .short  0
268; CHECK-NEXT:   .long
269define void @spilledValue(i64 %arg0, i64 %arg1, i64 %arg2, i64 %arg3, i64 %arg4, i64 %l0, i64 %l1, i64 %l2, i64 %l3, i64 %l4, i64 %l5, i64 %l6, i64 %l7, i64 %l8, i64 %l9, i64 %l10, i64 %l11, i64 %l12, i64 %l13, i64 %l14, i64 %l15, i64 %l16, i64 %l17, i64 %l18, i64 %l19, i64 %l20, i64 %l21, i64 %l22, i64 %l23, i64 %l24, i64 %l25, i64 %l26, i64 %l27) {
270entry:
271  call void (i64, i32, i8*, i32, ...) @llvm.experimental.patchpoint.void(i64 11, i32 20, i8* null, i32 5, i64 %arg0, i64 %arg1, i64 %arg2, i64 %arg3, i64 %arg4, i64 %l0, i64 %l1, i64 %l2, i64 %l3, i64 %l4, i64 %l5, i64 %l6, i64 %l7, i64 %l8, i64 %l9, i64 %l10, i64 %l11, i64 %l12, i64 %l13, i64 %l14, i64 %l15, i64 %l16, i64 %l17, i64 %l18, i64 %l19, i64 %l20, i64 %l21, i64 %l22, i64 %l23, i64 %l24, i64 %l25, i64 %l26, i64 %l27)
272  ret void
273}
274
275; Spilled stack map values.
276;
277; Verify 23 stack map entries.
278;
279; CHECK-LABEL:  .long L{{.*}}-_spilledStackMapValue
280; CHECK-NEXT:   .short 0
281; CHECK-NEXT:   .short 30
282;
283; Check that at least one is a spilled entry from RBP.
284; Location: Indirect FP + ...
285; CHECK:        .byte 3
286; CHECK-NEXT:   .byte 0
287; CHECK-NEXT:   .short
288; CHECK-NEXT:   .short 29
289; CHECK-NEXT:   .short  0
290; CHECK-NEXT:   .long
291define webkit_jscc void @spilledStackMapValue(i64 %l0, i64 %l1, i64 %l2, i64 %l3, i64 %l4, i64 %l5, i64 %l6, i64 %l7, i64 %l8, i64 %l9, i64 %l10, i64 %l11, i64 %l12, i64 %l13, i64 %l14, i64 %l15, i64 %l16, i64 %l17, i64 %l18, i64 %l19, i64 %l20, i64 %l21, i64 %l22, i64 %l23, i64 %l24, i64 %l25, i64 %l26, i64 %l27, i64 %l28, i64 %l29) {
292entry:
293  call void (i64, i32, ...) @llvm.experimental.stackmap(i64 12, i32 16, i64 %l0, i64 %l1, i64 %l2, i64 %l3, i64 %l4, i64 %l5, i64 %l6, i64 %l7, i64 %l8, i64 %l9, i64 %l10, i64 %l11, i64 %l12, i64 %l13, i64 %l14, i64 %l15, i64 %l16, i64 %l17, i64 %l18, i64 %l19, i64 %l20, i64 %l21, i64 %l22, i64 %l23, i64 %l24, i64 %l25, i64 %l26, i64 %l27, i64 %l28, i64 %l29)
294  ret void
295}
296
297
298; Map a constant value.
299;
300; CHECK-LABEL:  .long L{{.*}}-_liveConstant
301; CHECK-NEXT:   .short 0
302; 1 location
303; CHECK-NEXT:   .short 1
304; Loc 0: SmallConstant
305; CHECK-NEXT:   .byte   4
306; CHECK-NEXT:   .byte   0
307; CHECK-NEXT:   .short  8
308; CHECK-NEXT:   .short  0
309; CHECK-NEXT:   .short  0
310; CHECK-NEXT:   .long   33
311
312define void @liveConstant() {
313  tail call void (i64, i32, ...) @llvm.experimental.stackmap(i64 15, i32 8, i32 33)
314  ret void
315}
316
317; Map a value when LR is the only free register.
318;
319; CHECK-LABEL:  .long L{{.*}}-_clobberLR
320; CHECK-NEXT:   .short 0
321; 1 location
322; CHECK-NEXT:   .short 1
323; Loc 0: Indirect FP (r29) - offset
324; CHECK-NEXT:   .byte   3
325; CHECK-NEXT:   .byte   0
326; CHECK-NEXT:   .short  4
327; CHECK-NEXT:   .short  29
328; CHECK-NEXT:   .short  0
329; CHECK-NEXT:   .long   -{{[0-9]+}}
330define void @clobberLR(i32 %a) {
331  tail call void asm sideeffect "nop", "~{x0},~{x1},~{x2},~{x3},~{x4},~{x5},~{x6},~{x7},~{x8},~{x9},~{x10},~{x11},~{x12},~{x13},~{x14},~{x15},~{x16},~{x17},~{x18},~{x19},~{x20},~{x21},~{x22},~{x23},~{x24},~{x25},~{x26},~{x27},~{x28},~{x29},~{x31}"() nounwind
332  tail call void (i64, i32, ...) @llvm.experimental.stackmap(i64 16, i32 8, i32 %a)
333  ret void
334}
335
336declare void @llvm.experimental.stackmap(i64, i32, ...)
337declare void @llvm.experimental.patchpoint.void(i64, i32, i8*, i32, ...)
338declare i64 @llvm.experimental.patchpoint.i64(i64, i32, i8*, i32, ...)
339