1 //===-- X86CallingConv.td - Calling Conventions X86 32/64 --*- tablegen -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This describes the calling conventions for the X86-32 and X86-64
12 //===----------------------------------------------------------------------===//
14 /// CCIfSubtarget - Match if the current subtarget has a feature F.
15 class CCIfSubtarget<string F, CCAction A>
16 : CCIf<!strconcat("static_cast<const X86Subtarget&>"
17 "(State.getMachineFunction().getSubtarget()).", F),
20 /// CCIfNotSubtarget - Match if the current subtarget doesn't has a feature F.
21 class CCIfNotSubtarget<string F, CCAction A>
22 : CCIf<!strconcat("!static_cast<const X86Subtarget&>"
23 "(State.getMachineFunction().getSubtarget()).", F),
26 // Register classes for RegCall
27 class RC_X86_RegCall {
28 list<Register> GPR_8 = [];
29 list<Register> GPR_16 = [];
30 list<Register> GPR_32 = [];
31 list<Register> GPR_64 = [];
32 list<Register> FP_CALL = [FP0];
33 list<Register> FP_RET = [FP0, FP1];
34 list<Register> XMM = [];
35 list<Register> YMM = [];
36 list<Register> ZMM = [];
39 // RegCall register classes for 32 bits
40 def RC_X86_32_RegCall : RC_X86_RegCall {
41 let GPR_8 = [AL, CL, DL, DIL, SIL];
42 let GPR_16 = [AX, CX, DX, DI, SI];
43 let GPR_32 = [EAX, ECX, EDX, EDI, ESI];
44 let GPR_64 = [RAX]; ///< Not actually used, but AssignToReg can't handle []
45 ///< \todo Fix AssignToReg to enable empty lists
46 let XMM = [XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7];
47 let YMM = [YMM0, YMM1, YMM2, YMM3, YMM4, YMM5, YMM6, YMM7];
48 let ZMM = [ZMM0, ZMM1, ZMM2, ZMM3, ZMM4, ZMM5, ZMM6, ZMM7];
51 class RC_X86_64_RegCall : RC_X86_RegCall {
52 let XMM = [XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
53 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15];
54 let YMM = [YMM0, YMM1, YMM2, YMM3, YMM4, YMM5, YMM6, YMM7,
55 YMM8, YMM9, YMM10, YMM11, YMM12, YMM13, YMM14, YMM15];
56 let ZMM = [ZMM0, ZMM1, ZMM2, ZMM3, ZMM4, ZMM5, ZMM6, ZMM7,
57 ZMM8, ZMM9, ZMM10, ZMM11, ZMM12, ZMM13, ZMM14, ZMM15];
60 def RC_X86_64_RegCall_Win : RC_X86_64_RegCall {
61 let GPR_8 = [AL, CL, DL, DIL, SIL, R8B, R9B, R10B, R11B, R12B, R14B, R15B];
62 let GPR_16 = [AX, CX, DX, DI, SI, R8W, R9W, R10W, R11W, R12W, R14W, R15W];
63 let GPR_32 = [EAX, ECX, EDX, EDI, ESI, R8D, R9D, R10D, R11D, R12D, R14D, R15D];
64 let GPR_64 = [RAX, RCX, RDX, RDI, RSI, R8, R9, R10, R11, R12, R14, R15];
67 def RC_X86_64_RegCall_SysV : RC_X86_64_RegCall {
68 let GPR_8 = [AL, CL, DL, DIL, SIL, R8B, R9B, R12B, R13B, R14B, R15B];
69 let GPR_16 = [AX, CX, DX, DI, SI, R8W, R9W, R12W, R13W, R14W, R15W];
70 let GPR_32 = [EAX, ECX, EDX, EDI, ESI, R8D, R9D, R12D, R13D, R14D, R15D];
71 let GPR_64 = [RAX, RCX, RDX, RDI, RSI, R8, R9, R12, R13, R14, R15];
74 // X86-64 Intel regcall calling convention.
75 multiclass X86_RegCall_base<RC_X86_RegCall RC> {
76 def CC_#NAME : CallingConv<[
77 // Handles byval parameters.
78 CCIfSubtarget<"is64Bit()", CCIfByVal<CCPassByVal<8, 8>>>,
79 CCIfByVal<CCPassByVal<4, 4>>,
81 // Promote i1/i8/i16/v1i1 arguments to i32.
82 CCIfType<[i1, i8, i16, v1i1], CCPromoteToType<i32>>,
84 // Promote v8i1/v16i1/v32i1 arguments to i32.
85 CCIfType<[v8i1, v16i1, v32i1], CCPromoteToType<i32>>,
87 // bool, char, int, enum, long, pointer --> GPR
88 CCIfType<[i32], CCAssignToReg<RC.GPR_32>>,
90 // long long, __int64 --> GPR
91 CCIfType<[i64], CCAssignToReg<RC.GPR_64>>,
93 // __mmask64 (v64i1) --> GPR64 (for x64) or 2 x GPR32 (for IA32)
94 CCIfType<[v64i1], CCPromoteToType<i64>>,
95 CCIfSubtarget<"is64Bit()", CCIfType<[i64],
96 CCAssignToReg<RC.GPR_64>>>,
97 CCIfSubtarget<"is32Bit()", CCIfType<[i64],
98 CCCustom<"CC_X86_32_RegCall_Assign2Regs">>>,
100 // float, double, float128 --> XMM
101 // In the case of SSE disabled --> save to stack
102 CCIfType<[f32, f64, f128],
103 CCIfSubtarget<"hasSSE1()", CCAssignToReg<RC.XMM>>>,
105 // long double --> FP
106 CCIfType<[f80], CCAssignToReg<RC.FP_CALL>>,
108 // __m128, __m128i, __m128d --> XMM
109 // In the case of SSE disabled --> save to stack
110 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
111 CCIfSubtarget<"hasSSE1()", CCAssignToReg<RC.XMM>>>,
113 // __m256, __m256i, __m256d --> YMM
114 // In the case of SSE disabled --> save to stack
115 CCIfType<[v32i8, v16i16, v8i32, v4i64, v8f32, v4f64],
116 CCIfSubtarget<"hasAVX()", CCAssignToReg<RC.YMM>>>,
118 // __m512, __m512i, __m512d --> ZMM
119 // In the case of SSE disabled --> save to stack
120 CCIfType<[v64i8, v32i16, v16i32, v8i64, v16f32, v8f64],
121 CCIfSubtarget<"hasAVX512()",CCAssignToReg<RC.ZMM>>>,
123 // If no register was found -> assign to stack
125 // In 64 bit, assign 64/32 bit values to 8 byte stack
126 CCIfSubtarget<"is64Bit()", CCIfType<[i32, i64, f32, f64],
127 CCAssignToStack<8, 8>>>,
129 // In 32 bit, assign 64/32 bit values to 8/4 byte stack
130 CCIfType<[i32, f32], CCAssignToStack<4, 4>>,
131 CCIfType<[i64, f64], CCAssignToStack<8, 4>>,
133 // MMX type gets 8 byte slot in stack , while alignment depends on target
134 CCIfSubtarget<"is64Bit()", CCIfType<[x86mmx], CCAssignToStack<8, 8>>>,
135 CCIfType<[x86mmx], CCAssignToStack<8, 4>>,
137 // float 128 get stack slots whose size and alignment depends
139 CCIfType<[f80, f128], CCAssignToStack<0, 0>>,
141 // Vectors get 16-byte stack slots that are 16-byte aligned.
142 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
143 CCAssignToStack<16, 16>>,
145 // 256-bit vectors get 32-byte stack slots that are 32-byte aligned.
146 CCIfType<[v32i8, v16i16, v8i32, v4i64, v8f32, v4f64],
147 CCAssignToStack<32, 32>>,
149 // 512-bit vectors get 64-byte stack slots that are 64-byte aligned.
150 CCIfType<[v64i8, v32i16, v16i32, v8i64, v16f32, v8f64],
151 CCAssignToStack<64, 64>>
154 def RetCC_#NAME : CallingConv<[
155 // Promote i1, v1i1, v8i1 arguments to i8.
156 CCIfType<[i1, v1i1, v8i1], CCPromoteToType<i8>>,
158 // Promote v16i1 arguments to i16.
159 CCIfType<[v16i1], CCPromoteToType<i16>>,
161 // Promote v32i1 arguments to i32.
162 CCIfType<[v32i1], CCPromoteToType<i32>>,
164 // bool, char, int, enum, long, pointer --> GPR
165 CCIfType<[i8], CCAssignToReg<RC.GPR_8>>,
166 CCIfType<[i16], CCAssignToReg<RC.GPR_16>>,
167 CCIfType<[i32], CCAssignToReg<RC.GPR_32>>,
169 // long long, __int64 --> GPR
170 CCIfType<[i64], CCAssignToReg<RC.GPR_64>>,
172 // __mmask64 (v64i1) --> GPR64 (for x64) or 2 x GPR32 (for IA32)
173 CCIfType<[v64i1], CCPromoteToType<i64>>,
174 CCIfSubtarget<"is64Bit()", CCIfType<[i64],
175 CCAssignToReg<RC.GPR_64>>>,
176 CCIfSubtarget<"is32Bit()", CCIfType<[i64],
177 CCCustom<"CC_X86_32_RegCall_Assign2Regs">>>,
179 // long double --> FP
180 CCIfType<[f80], CCAssignToReg<RC.FP_RET>>,
182 // float, double, float128 --> XMM
183 CCIfType<[f32, f64, f128],
184 CCIfSubtarget<"hasSSE1()", CCAssignToReg<RC.XMM>>>,
186 // __m128, __m128i, __m128d --> XMM
187 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
188 CCIfSubtarget<"hasSSE1()", CCAssignToReg<RC.XMM>>>,
190 // __m256, __m256i, __m256d --> YMM
191 CCIfType<[v32i8, v16i16, v8i32, v4i64, v8f32, v4f64],
192 CCIfSubtarget<"hasAVX()", CCAssignToReg<RC.YMM>>>,
194 // __m512, __m512i, __m512d --> ZMM
195 CCIfType<[v64i8, v32i16, v16i32, v8i64, v16f32, v8f64],
196 CCIfSubtarget<"hasAVX512()", CCAssignToReg<RC.ZMM>>>
200 //===----------------------------------------------------------------------===//
201 // Return Value Calling Conventions
202 //===----------------------------------------------------------------------===//
204 // Return-value conventions common to all X86 CC's.
205 def RetCC_X86Common : CallingConv<[
206 // Scalar values are returned in AX first, then DX. For i8, the ABI
207 // requires the values to be in AL and AH, however this code uses AL and DL
208 // instead. This is because using AH for the second register conflicts with
209 // the way LLVM does multiple return values -- a return of {i16,i8} would end
210 // up in AX and AH, which overlap. Front-ends wishing to conform to the ABI
211 // for functions that return two i8 values are currently expected to pack the
212 // values into an i16 (which uses AX, and thus AL:AH).
214 // For code that doesn't care about the ABI, we allow returning more than two
215 // integer values in registers.
216 CCIfType<[v1i1], CCPromoteToType<i8>>,
217 CCIfType<[i1], CCPromoteToType<i8>>,
218 CCIfType<[i8] , CCAssignToReg<[AL, DL, CL]>>,
219 CCIfType<[i16], CCAssignToReg<[AX, DX, CX]>>,
220 CCIfType<[i32], CCAssignToReg<[EAX, EDX, ECX]>>,
221 CCIfType<[i64], CCAssignToReg<[RAX, RDX, RCX]>>,
223 // Boolean vectors of AVX-512 are returned in SIMD registers.
224 // The call from AVX to AVX-512 function should work,
225 // since the boolean types in AVX/AVX2 are promoted by default.
226 CCIfType<[v2i1], CCPromoteToType<v2i64>>,
227 CCIfType<[v4i1], CCPromoteToType<v4i32>>,
228 CCIfType<[v8i1], CCPromoteToType<v8i16>>,
229 CCIfType<[v16i1], CCPromoteToType<v16i8>>,
230 CCIfType<[v32i1], CCPromoteToType<v32i8>>,
231 CCIfType<[v64i1], CCPromoteToType<v64i8>>,
233 // Vector types are returned in XMM0 and XMM1, when they fit. XMM2 and XMM3
234 // can only be used by ABI non-compliant code. If the target doesn't have XMM
235 // registers, it won't have vector types.
236 CCIfType<[v16i8, v8i16, v4i32, v2i64, v8f16, v4f32, v2f64],
237 CCAssignToReg<[XMM0,XMM1,XMM2,XMM3]>>,
239 // 256-bit vectors are returned in YMM0 and XMM1, when they fit. YMM2 and YMM3
240 // can only be used by ABI non-compliant code. This vector type is only
241 // supported while using the AVX target feature.
242 CCIfType<[v32i8, v16i16, v8i32, v4i64, v16f16, v8f32, v4f64],
243 CCAssignToReg<[YMM0,YMM1,YMM2,YMM3]>>,
245 // 512-bit vectors are returned in ZMM0 and ZMM1, when they fit. ZMM2 and ZMM3
246 // can only be used by ABI non-compliant code. This vector type is only
247 // supported while using the AVX-512 target feature.
248 CCIfType<[v64i8, v32i16, v16i32, v8i64, v32f16, v16f32, v8f64],
249 CCAssignToReg<[ZMM0,ZMM1,ZMM2,ZMM3]>>,
251 // MMX vector types are always returned in MM0. If the target doesn't have
252 // MM0, it doesn't support these vector types.
253 CCIfType<[x86mmx], CCAssignToReg<[MM0]>>,
255 // Long double types are always returned in FP0 (even with SSE),
257 CCIfNotSubtarget<"isTargetWin64()", CCIfType<[f80], CCAssignToReg<[FP0, FP1]>>>
260 // X86-32 C return-value convention.
261 def RetCC_X86_32_C : CallingConv<[
262 // The X86-32 calling convention returns FP values in FP0, unless marked
263 // with "inreg" (used here to distinguish one kind of reg from another,
264 // weirdly; this is really the sse-regparm calling convention) in which
265 // case they use XMM0, otherwise it is the same as the common X86 calling
267 CCIfInReg<CCIfSubtarget<"hasSSE2()",
268 CCIfType<[f32, f64], CCAssignToReg<[XMM0,XMM1,XMM2]>>>>,
269 CCIfType<[f32,f64], CCAssignToReg<[FP0, FP1]>>,
270 CCIfType<[f16], CCAssignToReg<[XMM0,XMM1,XMM2]>>,
271 CCDelegateTo<RetCC_X86Common>
274 // X86-32 FastCC return-value convention.
275 def RetCC_X86_32_Fast : CallingConv<[
276 // The X86-32 fastcc returns 1, 2, or 3 FP values in XMM0-2 if the target has
278 // This can happen when a float, 2 x float, or 3 x float vector is split by
279 // target lowering, and is returned in 1-3 sse regs.
280 CCIfType<[f32], CCIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0,XMM1,XMM2]>>>,
281 CCIfType<[f64], CCIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0,XMM1,XMM2]>>>,
283 // For integers, ECX can be used as an extra return register
284 CCIfType<[i8], CCAssignToReg<[AL, DL, CL]>>,
285 CCIfType<[i16], CCAssignToReg<[AX, DX, CX]>>,
286 CCIfType<[i32], CCAssignToReg<[EAX, EDX, ECX]>>,
288 // Otherwise, it is the same as the common X86 calling convention.
289 CCDelegateTo<RetCC_X86Common>
292 // Intel_OCL_BI return-value convention.
293 def RetCC_Intel_OCL_BI : CallingConv<[
294 // Vector types are returned in XMM0,XMM1,XMMM2 and XMM3.
295 CCIfType<[f32, f64, v4i32, v2i64, v4f32, v2f64],
296 CCAssignToReg<[XMM0,XMM1,XMM2,XMM3]>>,
298 // 256-bit FP vectors
299 // No more than 4 registers
300 CCIfType<[v8f32, v4f64, v8i32, v4i64],
301 CCAssignToReg<[YMM0,YMM1,YMM2,YMM3]>>,
303 // 512-bit FP vectors
304 CCIfType<[v16f32, v8f64, v16i32, v8i64],
305 CCAssignToReg<[ZMM0,ZMM1,ZMM2,ZMM3]>>,
307 // i32, i64 in the standard way
308 CCDelegateTo<RetCC_X86Common>
311 // X86-32 HiPE return-value convention.
312 def RetCC_X86_32_HiPE : CallingConv<[
313 // Promote all types to i32
314 CCIfType<[i8, i16], CCPromoteToType<i32>>,
316 // Return: HP, P, VAL1, VAL2
317 CCIfType<[i32], CCAssignToReg<[ESI, EBP, EAX, EDX]>>
320 // X86-32 Vectorcall return-value convention.
321 def RetCC_X86_32_VectorCall : CallingConv<[
322 // Floating Point types are returned in XMM0,XMM1,XMMM2 and XMM3.
323 CCIfType<[f32, f64, f128],
324 CCAssignToReg<[XMM0,XMM1,XMM2,XMM3]>>,
326 // Return integers in the standard way.
327 CCDelegateTo<RetCC_X86Common>
330 // X86-64 C return-value convention.
331 def RetCC_X86_64_C : CallingConv<[
332 // The X86-64 calling convention always returns FP values in XMM0.
333 CCIfType<[f16], CCAssignToReg<[XMM0, XMM1]>>,
334 CCIfType<[f32], CCAssignToReg<[XMM0, XMM1]>>,
335 CCIfType<[f64], CCAssignToReg<[XMM0, XMM1]>>,
336 CCIfType<[f128], CCAssignToReg<[XMM0, XMM1]>>,
338 // MMX vector types are always returned in XMM0.
339 CCIfType<[x86mmx], CCAssignToReg<[XMM0, XMM1]>>,
341 // Pointers are always returned in full 64-bit registers.
342 CCIfPtr<CCCustom<"CC_X86_64_Pointer">>,
344 CCIfSwiftError<CCIfType<[i64], CCAssignToReg<[R12]>>>,
346 CCDelegateTo<RetCC_X86Common>
349 // X86-Win64 C return-value convention.
350 def RetCC_X86_Win64_C : CallingConv<[
351 // The X86-Win64 calling convention always returns __m64 values in RAX.
352 CCIfType<[x86mmx], CCBitConvertToType<i64>>,
354 // GCC returns FP values in RAX on Win64.
355 CCIfType<[f32], CCIfNotSubtarget<"hasSSE1()", CCBitConvertToType<i32>>>,
356 CCIfType<[f64], CCIfNotSubtarget<"hasSSE1()", CCBitConvertToType<i64>>>,
358 // Otherwise, everything is the same as 'normal' X86-64 C CC.
359 CCDelegateTo<RetCC_X86_64_C>
362 // X86-64 vectorcall return-value convention.
363 def RetCC_X86_64_Vectorcall : CallingConv<[
364 // Vectorcall calling convention always returns FP values in XMMs.
365 CCIfType<[f32, f64, f128],
366 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3]>>,
368 // Otherwise, everything is the same as Windows X86-64 C CC.
369 CCDelegateTo<RetCC_X86_Win64_C>
372 // X86-64 HiPE return-value convention.
373 def RetCC_X86_64_HiPE : CallingConv<[
374 // Promote all types to i64
375 CCIfType<[i8, i16, i32], CCPromoteToType<i64>>,
377 // Return: HP, P, VAL1, VAL2
378 CCIfType<[i64], CCAssignToReg<[R15, RBP, RAX, RDX]>>
381 // X86-64 WebKit_JS return-value convention.
382 def RetCC_X86_64_WebKit_JS : CallingConv<[
383 // Promote all types to i64
384 CCIfType<[i8, i16, i32], CCPromoteToType<i64>>,
387 CCIfType<[i64], CCAssignToReg<[RAX]>>
390 def RetCC_X86_64_Swift : CallingConv<[
392 CCIfSwiftError<CCIfType<[i64], CCAssignToReg<[R12]>>>,
394 // For integers, ECX, R8D can be used as extra return registers.
395 CCIfType<[v1i1], CCPromoteToType<i8>>,
396 CCIfType<[i1], CCPromoteToType<i8>>,
397 CCIfType<[i8] , CCAssignToReg<[AL, DL, CL, R8B]>>,
398 CCIfType<[i16], CCAssignToReg<[AX, DX, CX, R8W]>>,
399 CCIfType<[i32], CCAssignToReg<[EAX, EDX, ECX, R8D]>>,
400 CCIfType<[i64], CCAssignToReg<[RAX, RDX, RCX, R8]>>,
402 // XMM0, XMM1, XMM2 and XMM3 can be used to return FP values.
403 CCIfType<[f32], CCAssignToReg<[XMM0, XMM1, XMM2, XMM3]>>,
404 CCIfType<[f64], CCAssignToReg<[XMM0, XMM1, XMM2, XMM3]>>,
405 CCIfType<[f128], CCAssignToReg<[XMM0, XMM1, XMM2, XMM3]>>,
407 // MMX vector types are returned in XMM0, XMM1, XMM2 and XMM3.
408 CCIfType<[x86mmx], CCAssignToReg<[XMM0, XMM1, XMM2, XMM3]>>,
409 CCDelegateTo<RetCC_X86Common>
412 // X86-64 AnyReg return-value convention. No explicit register is specified for
413 // the return-value. The register allocator is allowed and expected to choose
414 // any free register.
416 // This calling convention is currently only supported by the stackmap and
417 // patchpoint intrinsics. All other uses will result in an assert on Debug
418 // builds. On Release builds we fallback to the X86 C calling convention.
419 def RetCC_X86_64_AnyReg : CallingConv<[
420 CCCustom<"CC_X86_AnyReg_Error">
423 // X86-64 HHVM return-value convention.
424 def RetCC_X86_64_HHVM: CallingConv<[
425 // Promote all types to i64
426 CCIfType<[i8, i16, i32], CCPromoteToType<i64>>,
428 // Return: could return in any GP register save RSP and R12.
429 CCIfType<[i64], CCAssignToReg<[RBX, RBP, RDI, RSI, RDX, RCX, R8, R9,
430 RAX, R10, R11, R13, R14, R15]>>
434 defm X86_32_RegCall :
435 X86_RegCall_base<RC_X86_32_RegCall>;
436 defm X86_Win64_RegCall :
437 X86_RegCall_base<RC_X86_64_RegCall_Win>;
438 defm X86_SysV64_RegCall :
439 X86_RegCall_base<RC_X86_64_RegCall_SysV>;
441 // This is the root return-value convention for the X86-32 backend.
442 def RetCC_X86_32 : CallingConv<[
443 // If FastCC, use RetCC_X86_32_Fast.
444 CCIfCC<"CallingConv::Fast", CCDelegateTo<RetCC_X86_32_Fast>>,
445 CCIfCC<"CallingConv::Tail", CCDelegateTo<RetCC_X86_32_Fast>>,
446 // CFGuard_Check never returns a value so does not need a RetCC.
447 // If HiPE, use RetCC_X86_32_HiPE.
448 CCIfCC<"CallingConv::HiPE", CCDelegateTo<RetCC_X86_32_HiPE>>,
449 CCIfCC<"CallingConv::X86_VectorCall", CCDelegateTo<RetCC_X86_32_VectorCall>>,
450 CCIfCC<"CallingConv::X86_RegCall", CCDelegateTo<RetCC_X86_32_RegCall>>,
452 // Otherwise, use RetCC_X86_32_C.
453 CCDelegateTo<RetCC_X86_32_C>
456 // This is the root return-value convention for the X86-64 backend.
457 def RetCC_X86_64 : CallingConv<[
458 // HiPE uses RetCC_X86_64_HiPE
459 CCIfCC<"CallingConv::HiPE", CCDelegateTo<RetCC_X86_64_HiPE>>,
461 // Handle JavaScript calls.
462 CCIfCC<"CallingConv::WebKit_JS", CCDelegateTo<RetCC_X86_64_WebKit_JS>>,
463 CCIfCC<"CallingConv::AnyReg", CCDelegateTo<RetCC_X86_64_AnyReg>>,
465 // Handle Swift calls.
466 CCIfCC<"CallingConv::Swift", CCDelegateTo<RetCC_X86_64_Swift>>,
467 CCIfCC<"CallingConv::SwiftTail", CCDelegateTo<RetCC_X86_64_Swift>>,
469 // Handle explicit CC selection
470 CCIfCC<"CallingConv::Win64", CCDelegateTo<RetCC_X86_Win64_C>>,
471 CCIfCC<"CallingConv::X86_64_SysV", CCDelegateTo<RetCC_X86_64_C>>,
473 // Handle Vectorcall CC
474 CCIfCC<"CallingConv::X86_VectorCall", CCDelegateTo<RetCC_X86_64_Vectorcall>>,
476 // Handle HHVM calls.
477 CCIfCC<"CallingConv::HHVM", CCDelegateTo<RetCC_X86_64_HHVM>>,
479 CCIfCC<"CallingConv::X86_RegCall",
480 CCIfSubtarget<"isTargetWin64()",
481 CCDelegateTo<RetCC_X86_Win64_RegCall>>>,
482 CCIfCC<"CallingConv::X86_RegCall", CCDelegateTo<RetCC_X86_SysV64_RegCall>>,
484 // Mingw64 and native Win64 use Win64 CC
485 CCIfSubtarget<"isTargetWin64()", CCDelegateTo<RetCC_X86_Win64_C>>,
487 // Otherwise, drop to normal X86-64 CC
488 CCDelegateTo<RetCC_X86_64_C>
491 // This is the return-value convention used for the entire X86 backend.
493 def RetCC_X86 : CallingConv<[
495 // Check if this is the Intel OpenCL built-ins calling convention
496 CCIfCC<"CallingConv::Intel_OCL_BI", CCDelegateTo<RetCC_Intel_OCL_BI>>,
498 CCIfSubtarget<"is64Bit()", CCDelegateTo<RetCC_X86_64>>,
499 CCDelegateTo<RetCC_X86_32>
502 //===----------------------------------------------------------------------===//
503 // X86-64 Argument Calling Conventions
504 //===----------------------------------------------------------------------===//
506 def CC_X86_64_C : CallingConv<[
507 // Handles byval parameters.
508 CCIfByVal<CCPassByVal<8, 8>>,
510 // Promote i1/i8/i16/v1i1 arguments to i32.
511 CCIfType<[i1, i8, i16, v1i1], CCPromoteToType<i32>>,
513 // The 'nest' parameter, if any, is passed in R10.
514 CCIfNest<CCIfSubtarget<"isTarget64BitILP32()", CCAssignToReg<[R10D]>>>,
515 CCIfNest<CCAssignToReg<[R10]>>,
517 // Pass SwiftSelf in a callee saved register.
518 CCIfSwiftSelf<CCIfType<[i64], CCAssignToReg<[R13]>>>,
520 // A SwiftError is passed in R12.
521 CCIfSwiftError<CCIfType<[i64], CCAssignToReg<[R12]>>>,
523 // Pass SwiftAsync in an otherwise callee saved register so that calls to
524 // normal functions don't need to save it somewhere.
525 CCIfSwiftAsync<CCIfType<[i64], CCAssignToReg<[R14]>>>,
527 // For Swift Calling Conventions, pass sret in %rax.
528 CCIfCC<"CallingConv::Swift",
529 CCIfSRet<CCIfType<[i64], CCAssignToReg<[RAX]>>>>,
530 CCIfCC<"CallingConv::SwiftTail",
531 CCIfSRet<CCIfType<[i64], CCAssignToReg<[RAX]>>>>,
533 // Pointers are always passed in full 64-bit registers.
534 CCIfPtr<CCCustom<"CC_X86_64_Pointer">>,
536 // The first 6 integer arguments are passed in integer registers.
537 CCIfType<[i32], CCAssignToReg<[EDI, ESI, EDX, ECX, R8D, R9D]>>,
538 CCIfType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8 , R9 ]>>,
540 // The first 8 MMX vector arguments are passed in XMM registers on Darwin.
542 CCIfSubtarget<"isTargetDarwin()",
543 CCIfSubtarget<"hasSSE2()",
544 CCPromoteToType<v2i64>>>>,
546 // Boolean vectors of AVX-512 are passed in SIMD registers.
547 // The call from AVX to AVX-512 function should work,
548 // since the boolean types in AVX/AVX2 are promoted by default.
549 CCIfType<[v2i1], CCPromoteToType<v2i64>>,
550 CCIfType<[v4i1], CCPromoteToType<v4i32>>,
551 CCIfType<[v8i1], CCPromoteToType<v8i16>>,
552 CCIfType<[v16i1], CCPromoteToType<v16i8>>,
553 CCIfType<[v32i1], CCPromoteToType<v32i8>>,
554 CCIfType<[v64i1], CCPromoteToType<v64i8>>,
556 // The first 8 FP/Vector arguments are passed in XMM registers.
557 CCIfType<[f16, f32, f64, f128, v16i8, v8i16, v4i32, v2i64, v8f16, v4f32, v2f64],
558 CCIfSubtarget<"hasSSE1()",
559 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7]>>>,
561 // The first 8 256-bit vector arguments are passed in YMM registers, unless
562 // this is a vararg function.
563 // FIXME: This isn't precisely correct; the x86-64 ABI document says that
564 // fixed arguments to vararg functions are supposed to be passed in
565 // registers. Actually modeling that would be a lot of work, though.
566 CCIfNotVarArg<CCIfType<[v32i8, v16i16, v8i32, v4i64, v16f16, v8f32, v4f64],
567 CCIfSubtarget<"hasAVX()",
568 CCAssignToReg<[YMM0, YMM1, YMM2, YMM3,
569 YMM4, YMM5, YMM6, YMM7]>>>>,
571 // The first 8 512-bit vector arguments are passed in ZMM registers.
572 CCIfNotVarArg<CCIfType<[v64i8, v32i16, v16i32, v8i64, v32f16, v16f32, v8f64],
573 CCIfSubtarget<"hasAVX512()",
574 CCAssignToReg<[ZMM0, ZMM1, ZMM2, ZMM3, ZMM4, ZMM5, ZMM6, ZMM7]>>>>,
576 // Integer/FP values get stored in stack slots that are 8 bytes in size and
577 // 8-byte aligned if there are no more registers to hold them.
578 CCIfType<[i32, i64, f16, f32, f64], CCAssignToStack<8, 8>>,
580 // Long doubles get stack slots whose size and alignment depends on the
582 CCIfType<[f80, f128], CCAssignToStack<0, 0>>,
584 // Vectors get 16-byte stack slots that are 16-byte aligned.
585 CCIfType<[v16i8, v8i16, v4i32, v2i64, v8f16, v4f32, v2f64], CCAssignToStack<16, 16>>,
587 // 256-bit vectors get 32-byte stack slots that are 32-byte aligned.
588 CCIfType<[v32i8, v16i16, v8i32, v4i64, v16f16, v8f32, v4f64],
589 CCAssignToStack<32, 32>>,
591 // 512-bit vectors get 64-byte stack slots that are 64-byte aligned.
592 CCIfType<[v64i8, v32i16, v16i32, v8i64, v32f16, v16f32, v8f64],
593 CCAssignToStack<64, 64>>
596 // Calling convention for X86-64 HHVM.
597 def CC_X86_64_HHVM : CallingConv<[
598 // Use all/any GP registers for args, except RSP.
599 CCIfType<[i64], CCAssignToReg<[RBX, R12, RBP, R15,
600 RDI, RSI, RDX, RCX, R8, R9,
601 RAX, R10, R11, R13, R14]>>
604 // Calling convention for helper functions in HHVM.
605 def CC_X86_64_HHVM_C : CallingConv<[
606 // Pass the first argument in RBP.
607 CCIfType<[i64], CCAssignToReg<[RBP]>>,
609 // Otherwise it's the same as the regular C calling convention.
610 CCDelegateTo<CC_X86_64_C>
613 // Calling convention used on Win64
614 def CC_X86_Win64_C : CallingConv<[
615 // FIXME: Handle varargs.
617 // Byval aggregates are passed by pointer
618 CCIfByVal<CCPassIndirect<i64>>,
620 // Promote i1/v1i1 arguments to i8.
621 CCIfType<[i1, v1i1], CCPromoteToType<i8>>,
623 // The 'nest' parameter, if any, is passed in R10.
624 CCIfNest<CCAssignToReg<[R10]>>,
626 // A SwiftError is passed in R12.
627 CCIfSwiftError<CCIfType<[i64], CCAssignToReg<[R12]>>>,
629 // Pass SwiftSelf in a callee saved register.
630 CCIfSwiftSelf<CCIfType<[i64], CCAssignToReg<[R13]>>>,
632 // Pass SwiftAsync in an otherwise callee saved register so that calls to
633 // normal functions don't need to save it somewhere.
634 CCIfSwiftAsync<CCIfType<[i64], CCAssignToReg<[R14]>>>,
636 // The 'CFGuardTarget' parameter, if any, is passed in RAX.
637 CCIfCFGuardTarget<CCAssignToReg<[RAX]>>,
639 // 128 bit vectors are passed by pointer
640 CCIfType<[v16i8, v8i16, v4i32, v2i64, v8f16, v4f32, v2f64], CCPassIndirect<i64>>,
642 // 256 bit vectors are passed by pointer
643 CCIfType<[v32i8, v16i16, v8i32, v4i64, v16f16, v8f32, v4f64], CCPassIndirect<i64>>,
645 // 512 bit vectors are passed by pointer
646 CCIfType<[v64i8, v32i16, v16i32, v32f16, v16f32, v8f64, v8i64], CCPassIndirect<i64>>,
648 // Long doubles are passed by pointer
649 CCIfType<[f80], CCPassIndirect<i64>>,
651 // The first 4 MMX vector arguments are passed in GPRs.
652 CCIfType<[x86mmx], CCBitConvertToType<i64>>,
654 // If SSE was disabled, pass FP values smaller than 64-bits as integers in
655 // GPRs or on the stack.
656 CCIfType<[f32], CCIfNotSubtarget<"hasSSE1()", CCBitConvertToType<i32>>>,
657 CCIfType<[f64], CCIfNotSubtarget<"hasSSE1()", CCBitConvertToType<i64>>>,
659 // The first 4 FP/Vector arguments are passed in XMM registers.
660 CCIfType<[f16, f32, f64],
661 CCAssignToRegWithShadow<[XMM0, XMM1, XMM2, XMM3],
662 [RCX , RDX , R8 , R9 ]>>,
664 // The first 4 integer arguments are passed in integer registers.
665 CCIfType<[i8 ], CCAssignToRegWithShadow<[CL , DL , R8B , R9B ],
666 [XMM0, XMM1, XMM2, XMM3]>>,
667 CCIfType<[i16], CCAssignToRegWithShadow<[CX , DX , R8W , R9W ],
668 [XMM0, XMM1, XMM2, XMM3]>>,
669 CCIfType<[i32], CCAssignToRegWithShadow<[ECX , EDX , R8D , R9D ],
670 [XMM0, XMM1, XMM2, XMM3]>>,
672 // Do not pass the sret argument in RCX, the Win64 thiscall calling
673 // convention requires "this" to be passed in RCX.
674 CCIfCC<"CallingConv::X86_ThisCall",
675 CCIfSRet<CCIfType<[i64], CCAssignToRegWithShadow<[RDX , R8 , R9 ],
676 [XMM1, XMM2, XMM3]>>>>,
678 CCIfType<[i64], CCAssignToRegWithShadow<[RCX , RDX , R8 , R9 ],
679 [XMM0, XMM1, XMM2, XMM3]>>,
681 // Integer/FP values get stored in stack slots that are 8 bytes in size and
682 // 8-byte aligned if there are no more registers to hold them.
683 CCIfType<[i8, i16, i32, i64, f16, f32, f64], CCAssignToStack<8, 8>>
686 def CC_X86_Win64_VectorCall : CallingConv<[
687 CCCustom<"CC_X86_64_VectorCall">,
689 // Delegate to fastcall to handle integer types.
690 CCDelegateTo<CC_X86_Win64_C>
694 def CC_X86_64_GHC : CallingConv<[
695 // Promote i8/i16/i32 arguments to i64.
696 CCIfType<[i8, i16, i32], CCPromoteToType<i64>>,
698 // Pass in STG registers: Base, Sp, Hp, R1, R2, R3, R4, R5, R6, SpLim
700 CCAssignToReg<[R13, RBP, R12, RBX, R14, RSI, RDI, R8, R9, R15]>>,
702 // Pass in STG registers: F1, F2, F3, F4, D1, D2
703 CCIfType<[f32, f64, v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
704 CCIfSubtarget<"hasSSE1()",
705 CCAssignToReg<[XMM1, XMM2, XMM3, XMM4, XMM5, XMM6]>>>,
707 CCIfType<[v32i8, v16i16, v8i32, v4i64, v8f32, v4f64],
708 CCIfSubtarget<"hasAVX()",
709 CCAssignToReg<[YMM1, YMM2, YMM3, YMM4, YMM5, YMM6]>>>,
711 CCIfType<[v64i8, v32i16, v16i32, v8i64, v16f32, v8f64],
712 CCIfSubtarget<"hasAVX512()",
713 CCAssignToReg<[ZMM1, ZMM2, ZMM3, ZMM4, ZMM5, ZMM6]>>>
716 def CC_X86_64_HiPE : CallingConv<[
717 // Promote i8/i16/i32 arguments to i64.
718 CCIfType<[i8, i16, i32], CCPromoteToType<i64>>,
720 // Pass in VM's registers: HP, P, ARG0, ARG1, ARG2, ARG3
721 CCIfType<[i64], CCAssignToReg<[R15, RBP, RSI, RDX, RCX, R8]>>,
723 // Integer/FP values get stored in stack slots that are 8 bytes in size and
724 // 8-byte aligned if there are no more registers to hold them.
725 CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>
728 def CC_X86_64_WebKit_JS : CallingConv<[
729 // Promote i8/i16 arguments to i32.
730 CCIfType<[i8, i16], CCPromoteToType<i32>>,
732 // Only the first integer argument is passed in register.
733 CCIfType<[i32], CCAssignToReg<[EAX]>>,
734 CCIfType<[i64], CCAssignToReg<[RAX]>>,
736 // The remaining integer arguments are passed on the stack. 32bit integer and
737 // floating-point arguments are aligned to 4 byte and stored in 4 byte slots.
738 // 64bit integer and floating-point arguments are aligned to 8 byte and stored
739 // in 8 byte stack slots.
740 CCIfType<[i32, f32], CCAssignToStack<4, 4>>,
741 CCIfType<[i64, f64], CCAssignToStack<8, 8>>
744 // No explicit register is specified for the AnyReg calling convention. The
745 // register allocator may assign the arguments to any free register.
747 // This calling convention is currently only supported by the stackmap and
748 // patchpoint intrinsics. All other uses will result in an assert on Debug
749 // builds. On Release builds we fallback to the X86 C calling convention.
750 def CC_X86_64_AnyReg : CallingConv<[
751 CCCustom<"CC_X86_AnyReg_Error">
754 //===----------------------------------------------------------------------===//
755 // X86 C Calling Convention
756 //===----------------------------------------------------------------------===//
758 /// CC_X86_32_Vector_Common - In all X86-32 calling conventions, extra vector
759 /// values are spilled on the stack.
760 def CC_X86_32_Vector_Common : CallingConv<[
761 // Other SSE vectors get 16-byte stack slots that are 16-byte aligned.
762 CCIfType<[v16i8, v8i16, v4i32, v2i64, v8f16, v4f32, v2f64],
763 CCAssignToStack<16, 16>>,
765 // 256-bit AVX vectors get 32-byte stack slots that are 32-byte aligned.
766 CCIfType<[v32i8, v16i16, v8i32, v4i64, v16f16, v8f32, v4f64],
767 CCAssignToStack<32, 32>>,
769 // 512-bit AVX 512-bit vectors get 64-byte stack slots that are 64-byte aligned.
770 CCIfType<[v64i8, v32i16, v16i32, v8i64, v32f16, v16f32, v8f64],
771 CCAssignToStack<64, 64>>
774 // CC_X86_32_Vector_Standard - The first 3 vector arguments are passed in
776 def CC_X86_32_Vector_Standard : CallingConv<[
777 // SSE vector arguments are passed in XMM registers.
778 CCIfNotVarArg<CCIfType<[v16i8, v8i16, v4i32, v2i64, v8f16, v4f32, v2f64],
779 CCAssignToReg<[XMM0, XMM1, XMM2]>>>,
781 // AVX 256-bit vector arguments are passed in YMM registers.
782 CCIfNotVarArg<CCIfType<[v32i8, v16i16, v8i32, v4i64, v16f16, v8f32, v4f64],
783 CCIfSubtarget<"hasAVX()",
784 CCAssignToReg<[YMM0, YMM1, YMM2]>>>>,
786 // AVX 512-bit vector arguments are passed in ZMM registers.
787 CCIfNotVarArg<CCIfType<[v64i8, v32i16, v16i32, v8i64, v32f16, v16f32, v8f64],
788 CCAssignToReg<[ZMM0, ZMM1, ZMM2]>>>,
790 CCDelegateTo<CC_X86_32_Vector_Common>
793 // CC_X86_32_Vector_Darwin - The first 4 vector arguments are passed in
795 def CC_X86_32_Vector_Darwin : CallingConv<[
796 // SSE vector arguments are passed in XMM registers.
797 CCIfNotVarArg<CCIfType<[v16i8, v8i16, v4i32, v2i64, v8f16, v4f32, v2f64],
798 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3]>>>,
800 // AVX 256-bit vector arguments are passed in YMM registers.
801 CCIfNotVarArg<CCIfType<[v32i8, v16i16, v8i32, v4i64, v16f16, v8f32, v4f64],
802 CCIfSubtarget<"hasAVX()",
803 CCAssignToReg<[YMM0, YMM1, YMM2, YMM3]>>>>,
805 // AVX 512-bit vector arguments are passed in ZMM registers.
806 CCIfNotVarArg<CCIfType<[v64i8, v32i16, v16i32, v8i64, v32f16, v16f32, v8f64],
807 CCAssignToReg<[ZMM0, ZMM1, ZMM2, ZMM3]>>>,
809 CCDelegateTo<CC_X86_32_Vector_Common>
812 /// CC_X86_32_Common - In all X86-32 calling conventions, extra integers and FP
813 /// values are spilled on the stack.
814 def CC_X86_32_Common : CallingConv<[
815 // Handles byval/preallocated parameters.
816 CCIfByVal<CCPassByVal<4, 4>>,
817 CCIfPreallocated<CCPassByVal<4, 4>>,
819 // The first 3 float or double arguments, if marked 'inreg' and if the call
820 // is not a vararg call and if SSE2 is available, are passed in SSE registers.
821 CCIfNotVarArg<CCIfInReg<CCIfType<[f32,f64],
822 CCIfSubtarget<"hasSSE2()",
823 CCAssignToReg<[XMM0,XMM1,XMM2]>>>>>,
825 CCIfNotVarArg<CCIfInReg<CCIfType<[f16], CCAssignToReg<[XMM0,XMM1,XMM2]>>>>,
827 // The first 3 __m64 vector arguments are passed in mmx registers if the
828 // call is not a vararg call.
829 CCIfNotVarArg<CCIfType<[x86mmx],
830 CCAssignToReg<[MM0, MM1, MM2]>>>,
832 CCIfType<[f16], CCAssignToStack<4, 4>>,
834 // Integer/Float values get stored in stack slots that are 4 bytes in
835 // size and 4-byte aligned.
836 CCIfType<[i32, f32], CCAssignToStack<4, 4>>,
838 // Doubles get 8-byte slots that are 4-byte aligned.
839 CCIfType<[f64], CCAssignToStack<8, 4>>,
841 // Long doubles get slots whose size depends on the subtarget.
842 CCIfType<[f80], CCAssignToStack<0, 4>>,
844 // Boolean vectors of AVX-512 are passed in SIMD registers.
845 // The call from AVX to AVX-512 function should work,
846 // since the boolean types in AVX/AVX2 are promoted by default.
847 CCIfType<[v2i1], CCPromoteToType<v2i64>>,
848 CCIfType<[v4i1], CCPromoteToType<v4i32>>,
849 CCIfType<[v8i1], CCPromoteToType<v8i16>>,
850 CCIfType<[v16i1], CCPromoteToType<v16i8>>,
851 CCIfType<[v32i1], CCPromoteToType<v32i8>>,
852 CCIfType<[v64i1], CCPromoteToType<v64i8>>,
854 // __m64 vectors get 8-byte stack slots that are 4-byte aligned. They are
855 // passed in the parameter area.
856 CCIfType<[x86mmx], CCAssignToStack<8, 4>>,
858 // Darwin passes vectors in a form that differs from the i386 psABI
859 CCIfSubtarget<"isTargetDarwin()", CCDelegateTo<CC_X86_32_Vector_Darwin>>,
861 // Otherwise, drop to 'normal' X86-32 CC
862 CCDelegateTo<CC_X86_32_Vector_Standard>
865 def CC_X86_32_C : CallingConv<[
866 // Promote i1/i8/i16/v1i1 arguments to i32.
867 CCIfType<[i1, i8, i16, v1i1], CCPromoteToType<i32>>,
869 // The 'nest' parameter, if any, is passed in ECX.
870 CCIfNest<CCAssignToReg<[ECX]>>,
872 // On swifttailcc pass swiftself in ECX.
873 CCIfCC<"CallingConv::SwiftTail",
874 CCIfSwiftSelf<CCIfType<[i32], CCAssignToReg<[ECX]>>>>,
876 // The first 3 integer arguments, if marked 'inreg' and if the call is not
877 // a vararg call, are passed in integer registers.
878 CCIfNotVarArg<CCIfInReg<CCIfType<[i32], CCAssignToReg<[EAX, EDX, ECX]>>>>,
880 // Otherwise, same as everything else.
881 CCDelegateTo<CC_X86_32_Common>
884 def CC_X86_32_MCU : CallingConv<[
885 // Handles byval parameters. Note that, like FastCC, we can't rely on
886 // the delegation to CC_X86_32_Common because that happens after code that
887 // puts arguments in registers.
888 CCIfByVal<CCPassByVal<4, 4>>,
890 // Promote i1/i8/i16/v1i1 arguments to i32.
891 CCIfType<[i1, i8, i16, v1i1], CCPromoteToType<i32>>,
893 // If the call is not a vararg call, some arguments may be passed
894 // in integer registers.
895 CCIfNotVarArg<CCIfType<[i32], CCCustom<"CC_X86_32_MCUInReg">>>,
897 // Otherwise, same as everything else.
898 CCDelegateTo<CC_X86_32_Common>
901 def CC_X86_32_FastCall : CallingConv<[
903 CCIfType<[i1], CCPromoteToType<i8>>,
905 // The 'nest' parameter, if any, is passed in EAX.
906 CCIfNest<CCAssignToReg<[EAX]>>,
908 // The first 2 integer arguments are passed in ECX/EDX
909 CCIfInReg<CCIfType<[ i8], CCAssignToReg<[ CL, DL]>>>,
910 CCIfInReg<CCIfType<[i16], CCAssignToReg<[ CX, DX]>>>,
911 CCIfInReg<CCIfType<[i32], CCAssignToReg<[ECX, EDX]>>>,
913 // Otherwise, same as everything else.
914 CCDelegateTo<CC_X86_32_Common>
917 def CC_X86_Win32_VectorCall : CallingConv<[
918 // Pass floating point in XMMs
919 CCCustom<"CC_X86_32_VectorCall">,
921 // Delegate to fastcall to handle integer types.
922 CCDelegateTo<CC_X86_32_FastCall>
925 def CC_X86_32_ThisCall_Common : CallingConv<[
926 // The first integer argument is passed in ECX
927 CCIfType<[i32], CCAssignToReg<[ECX]>>,
929 // Otherwise, same as everything else.
930 CCDelegateTo<CC_X86_32_Common>
933 def CC_X86_32_ThisCall_Mingw : CallingConv<[
934 // Promote i1/i8/i16/v1i1 arguments to i32.
935 CCIfType<[i1, i8, i16, v1i1], CCPromoteToType<i32>>,
937 CCDelegateTo<CC_X86_32_ThisCall_Common>
940 def CC_X86_32_ThisCall_Win : CallingConv<[
941 // Promote i1/i8/i16/v1i1 arguments to i32.
942 CCIfType<[i1, i8, i16, v1i1], CCPromoteToType<i32>>,
944 // Pass sret arguments indirectly through stack.
945 CCIfSRet<CCAssignToStack<4, 4>>,
947 CCDelegateTo<CC_X86_32_ThisCall_Common>
950 def CC_X86_32_ThisCall : CallingConv<[
951 CCIfSubtarget<"isTargetCygMing()", CCDelegateTo<CC_X86_32_ThisCall_Mingw>>,
952 CCDelegateTo<CC_X86_32_ThisCall_Win>
955 def CC_X86_32_FastCC : CallingConv<[
956 // Handles byval parameters. Note that we can't rely on the delegation
957 // to CC_X86_32_Common for this because that happens after code that
958 // puts arguments in registers.
959 CCIfByVal<CCPassByVal<4, 4>>,
961 // Promote i1/i8/i16/v1i1 arguments to i32.
962 CCIfType<[i1, i8, i16, v1i1], CCPromoteToType<i32>>,
964 // The 'nest' parameter, if any, is passed in EAX.
965 CCIfNest<CCAssignToReg<[EAX]>>,
967 // The first 2 integer arguments are passed in ECX/EDX
968 CCIfType<[i32], CCAssignToReg<[ECX, EDX]>>,
970 // The first 3 float or double arguments, if the call is not a vararg
971 // call and if SSE2 is available, are passed in SSE registers.
972 CCIfNotVarArg<CCIfType<[f32,f64],
973 CCIfSubtarget<"hasSSE2()",
974 CCAssignToReg<[XMM0,XMM1,XMM2]>>>>,
976 // Doubles get 8-byte slots that are 8-byte aligned.
977 CCIfType<[f64], CCAssignToStack<8, 8>>,
979 // Otherwise, same as everything else.
980 CCDelegateTo<CC_X86_32_Common>
983 def CC_X86_Win32_CFGuard_Check : CallingConv<[
984 // The CFGuard check call takes exactly one integer argument
985 // (i.e. the target function address), which is passed in ECX.
986 CCIfType<[i32], CCAssignToReg<[ECX]>>
989 def CC_X86_32_GHC : CallingConv<[
990 // Promote i8/i16 arguments to i32.
991 CCIfType<[i8, i16], CCPromoteToType<i32>>,
993 // Pass in STG registers: Base, Sp, Hp, R1
994 CCIfType<[i32], CCAssignToReg<[EBX, EBP, EDI, ESI]>>
997 def CC_X86_32_HiPE : CallingConv<[
998 // Promote i8/i16 arguments to i32.
999 CCIfType<[i8, i16], CCPromoteToType<i32>>,
1001 // Pass in VM's registers: HP, P, ARG0, ARG1, ARG2
1002 CCIfType<[i32], CCAssignToReg<[ESI, EBP, EAX, EDX, ECX]>>,
1004 // Integer/Float values get stored in stack slots that are 4 bytes in
1005 // size and 4-byte aligned.
1006 CCIfType<[i32, f32], CCAssignToStack<4, 4>>
1009 // X86-64 Intel OpenCL built-ins calling convention.
1010 def CC_Intel_OCL_BI : CallingConv<[
1012 CCIfType<[i32], CCIfSubtarget<"isTargetWin64()", CCAssignToReg<[ECX, EDX, R8D, R9D]>>>,
1013 CCIfType<[i64], CCIfSubtarget<"isTargetWin64()", CCAssignToReg<[RCX, RDX, R8, R9 ]>>>,
1015 CCIfType<[i32], CCIfSubtarget<"is64Bit()", CCAssignToReg<[EDI, ESI, EDX, ECX]>>>,
1016 CCIfType<[i64], CCIfSubtarget<"is64Bit()", CCAssignToReg<[RDI, RSI, RDX, RCX]>>>,
1018 CCIfType<[i32], CCAssignToStack<4, 4>>,
1020 // The SSE vector arguments are passed in XMM registers.
1021 CCIfType<[f32, f64, v4i32, v2i64, v4f32, v2f64],
1022 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3]>>,
1024 // The 256-bit vector arguments are passed in YMM registers.
1025 CCIfType<[v8f32, v4f64, v8i32, v4i64],
1026 CCAssignToReg<[YMM0, YMM1, YMM2, YMM3]>>,
1028 // The 512-bit vector arguments are passed in ZMM registers.
1029 CCIfType<[v16f32, v8f64, v16i32, v8i64],
1030 CCAssignToReg<[ZMM0, ZMM1, ZMM2, ZMM3]>>,
1032 // Pass masks in mask registers
1033 CCIfType<[v16i1, v8i1], CCAssignToReg<[K1]>>,
1035 CCIfSubtarget<"isTargetWin64()", CCDelegateTo<CC_X86_Win64_C>>,
1036 CCIfSubtarget<"is64Bit()", CCDelegateTo<CC_X86_64_C>>,
1037 CCDelegateTo<CC_X86_32_C>
1040 //===----------------------------------------------------------------------===//
1041 // X86 Root Argument Calling Conventions
1042 //===----------------------------------------------------------------------===//
1044 // This is the root argument convention for the X86-32 backend.
1045 def CC_X86_32 : CallingConv<[
1046 // X86_INTR calling convention is valid in MCU target and should override the
1047 // MCU calling convention. Thus, this should be checked before isTargetMCU().
1048 CCIfCC<"CallingConv::X86_INTR", CCCustom<"CC_X86_Intr">>,
1049 CCIfSubtarget<"isTargetMCU()", CCDelegateTo<CC_X86_32_MCU>>,
1050 CCIfCC<"CallingConv::X86_FastCall", CCDelegateTo<CC_X86_32_FastCall>>,
1051 CCIfCC<"CallingConv::X86_VectorCall", CCDelegateTo<CC_X86_Win32_VectorCall>>,
1052 CCIfCC<"CallingConv::X86_ThisCall", CCDelegateTo<CC_X86_32_ThisCall>>,
1053 CCIfCC<"CallingConv::CFGuard_Check", CCDelegateTo<CC_X86_Win32_CFGuard_Check>>,
1054 CCIfCC<"CallingConv::Fast", CCDelegateTo<CC_X86_32_FastCC>>,
1055 CCIfCC<"CallingConv::Tail", CCDelegateTo<CC_X86_32_FastCC>>,
1056 CCIfCC<"CallingConv::GHC", CCDelegateTo<CC_X86_32_GHC>>,
1057 CCIfCC<"CallingConv::HiPE", CCDelegateTo<CC_X86_32_HiPE>>,
1058 CCIfCC<"CallingConv::X86_RegCall", CCDelegateTo<CC_X86_32_RegCall>>,
1060 // Otherwise, drop to normal X86-32 CC
1061 CCDelegateTo<CC_X86_32_C>
1064 // This is the root argument convention for the X86-64 backend.
1065 def CC_X86_64 : CallingConv<[
1066 CCIfCC<"CallingConv::GHC", CCDelegateTo<CC_X86_64_GHC>>,
1067 CCIfCC<"CallingConv::HiPE", CCDelegateTo<CC_X86_64_HiPE>>,
1068 CCIfCC<"CallingConv::WebKit_JS", CCDelegateTo<CC_X86_64_WebKit_JS>>,
1069 CCIfCC<"CallingConv::AnyReg", CCDelegateTo<CC_X86_64_AnyReg>>,
1070 CCIfCC<"CallingConv::Win64", CCDelegateTo<CC_X86_Win64_C>>,
1071 CCIfCC<"CallingConv::X86_64_SysV", CCDelegateTo<CC_X86_64_C>>,
1072 CCIfCC<"CallingConv::X86_VectorCall", CCDelegateTo<CC_X86_Win64_VectorCall>>,
1073 CCIfCC<"CallingConv::HHVM", CCDelegateTo<CC_X86_64_HHVM>>,
1074 CCIfCC<"CallingConv::HHVM_C", CCDelegateTo<CC_X86_64_HHVM_C>>,
1075 CCIfCC<"CallingConv::X86_RegCall",
1076 CCIfSubtarget<"isTargetWin64()", CCDelegateTo<CC_X86_Win64_RegCall>>>,
1077 CCIfCC<"CallingConv::X86_RegCall", CCDelegateTo<CC_X86_SysV64_RegCall>>,
1078 CCIfCC<"CallingConv::X86_INTR", CCCustom<"CC_X86_Intr">>,
1080 // Mingw64 and native Win64 use Win64 CC
1081 CCIfSubtarget<"isTargetWin64()", CCDelegateTo<CC_X86_Win64_C>>,
1083 // Otherwise, drop to normal X86-64 CC
1084 CCDelegateTo<CC_X86_64_C>
1087 // This is the argument convention used for the entire X86 backend.
1089 def CC_X86 : CallingConv<[
1090 CCIfCC<"CallingConv::Intel_OCL_BI", CCDelegateTo<CC_Intel_OCL_BI>>,
1091 CCIfSubtarget<"is64Bit()", CCDelegateTo<CC_X86_64>>,
1092 CCDelegateTo<CC_X86_32>
1095 //===----------------------------------------------------------------------===//
1096 // Callee-saved Registers.
1097 //===----------------------------------------------------------------------===//
1099 def CSR_NoRegs : CalleeSavedRegs<(add)>;
1101 def CSR_32 : CalleeSavedRegs<(add ESI, EDI, EBX, EBP)>;
1102 def CSR_64 : CalleeSavedRegs<(add RBX, R12, R13, R14, R15, RBP)>;
1104 def CSR_64_SwiftError : CalleeSavedRegs<(sub CSR_64, R12)>;
1105 def CSR_64_SwiftTail : CalleeSavedRegs<(sub CSR_64, R13, R14)>;
1107 def CSR_32EHRet : CalleeSavedRegs<(add EAX, EDX, CSR_32)>;
1108 def CSR_64EHRet : CalleeSavedRegs<(add RAX, RDX, CSR_64)>;
1110 def CSR_Win64_NoSSE : CalleeSavedRegs<(add RBX, RBP, RDI, RSI, R12, R13, R14, R15)>;
1112 def CSR_Win64 : CalleeSavedRegs<(add CSR_Win64_NoSSE,
1113 (sequence "XMM%u", 6, 15))>;
1115 def CSR_Win64_SwiftError : CalleeSavedRegs<(sub CSR_Win64, R12)>;
1116 def CSR_Win64_SwiftTail : CalleeSavedRegs<(sub CSR_Win64, R13, R14)>;
1118 // The function used by Darwin to obtain the address of a thread-local variable
1119 // uses rdi to pass a single parameter and rax for the return value. All other
1120 // GPRs are preserved.
1121 def CSR_64_TLS_Darwin : CalleeSavedRegs<(add CSR_64, RCX, RDX, RSI,
1124 // CSRs that are handled by prologue, epilogue.
1125 def CSR_64_CXX_TLS_Darwin_PE : CalleeSavedRegs<(add RBP)>;
1127 // CSRs that are handled explicitly via copies.
1128 def CSR_64_CXX_TLS_Darwin_ViaCopy : CalleeSavedRegs<(sub CSR_64_TLS_Darwin, RBP)>;
1130 // All GPRs - except r11
1131 def CSR_64_RT_MostRegs : CalleeSavedRegs<(add CSR_64, RAX, RCX, RDX, RSI, RDI,
1134 // All registers - except r11
1135 def CSR_64_RT_AllRegs : CalleeSavedRegs<(add CSR_64_RT_MostRegs,
1136 (sequence "XMM%u", 0, 15))>;
1137 def CSR_64_RT_AllRegs_AVX : CalleeSavedRegs<(add CSR_64_RT_MostRegs,
1138 (sequence "YMM%u", 0, 15))>;
1140 def CSR_64_MostRegs : CalleeSavedRegs<(add RBX, RCX, RDX, RSI, RDI, R8, R9, R10,
1141 R11, R12, R13, R14, R15, RBP,
1142 (sequence "XMM%u", 0, 15))>;
1144 def CSR_32_AllRegs : CalleeSavedRegs<(add EAX, EBX, ECX, EDX, EBP, ESI,
1146 def CSR_32_AllRegs_SSE : CalleeSavedRegs<(add CSR_32_AllRegs,
1147 (sequence "XMM%u", 0, 7))>;
1148 def CSR_32_AllRegs_AVX : CalleeSavedRegs<(add CSR_32_AllRegs,
1149 (sequence "YMM%u", 0, 7))>;
1150 def CSR_32_AllRegs_AVX512 : CalleeSavedRegs<(add CSR_32_AllRegs,
1151 (sequence "ZMM%u", 0, 7),
1152 (sequence "K%u", 0, 7))>;
1154 def CSR_64_AllRegs : CalleeSavedRegs<(add CSR_64_MostRegs, RAX)>;
1155 def CSR_64_AllRegs_NoSSE : CalleeSavedRegs<(add RAX, RBX, RCX, RDX, RSI, RDI, R8, R9,
1156 R10, R11, R12, R13, R14, R15, RBP)>;
1157 def CSR_64_AllRegs_AVX : CalleeSavedRegs<(sub (add CSR_64_MostRegs, RAX,
1158 (sequence "YMM%u", 0, 15)),
1159 (sequence "XMM%u", 0, 15))>;
1160 def CSR_64_AllRegs_AVX512 : CalleeSavedRegs<(sub (add CSR_64_MostRegs, RAX,
1161 (sequence "ZMM%u", 0, 31),
1162 (sequence "K%u", 0, 7)),
1163 (sequence "XMM%u", 0, 15))>;
1165 // Standard C + YMM6-15
1166 def CSR_Win64_Intel_OCL_BI_AVX : CalleeSavedRegs<(add RBX, RBP, RDI, RSI, R12,
1168 (sequence "YMM%u", 6, 15))>;
1170 def CSR_Win64_Intel_OCL_BI_AVX512 : CalleeSavedRegs<(add RBX, RBP, RDI, RSI,
1172 (sequence "ZMM%u", 6, 21),
1174 //Standard C + XMM 8-15
1175 def CSR_64_Intel_OCL_BI : CalleeSavedRegs<(add CSR_64,
1176 (sequence "XMM%u", 8, 15))>;
1178 //Standard C + YMM 8-15
1179 def CSR_64_Intel_OCL_BI_AVX : CalleeSavedRegs<(add CSR_64,
1180 (sequence "YMM%u", 8, 15))>;
1182 def CSR_64_Intel_OCL_BI_AVX512 : CalleeSavedRegs<(add RBX, RSI, R14, R15,
1183 (sequence "ZMM%u", 16, 31),
1186 // Only R12 is preserved for PHP calls in HHVM.
1187 def CSR_64_HHVM : CalleeSavedRegs<(add R12)>;
1189 // Register calling convention preserves few GPR and XMM8-15
1190 def CSR_32_RegCall_NoSSE : CalleeSavedRegs<(add ESI, EDI, EBX, EBP)>;
1191 def CSR_32_RegCall : CalleeSavedRegs<(add CSR_32_RegCall_NoSSE,
1192 (sequence "XMM%u", 4, 7))>;
1193 def CSR_Win32_CFGuard_Check_NoSSE : CalleeSavedRegs<(add CSR_32_RegCall_NoSSE, ECX)>;
1194 def CSR_Win32_CFGuard_Check : CalleeSavedRegs<(add CSR_32_RegCall, ECX)>;
1195 def CSR_Win64_RegCall_NoSSE : CalleeSavedRegs<(add RBX, RBP,
1196 (sequence "R%u", 10, 15))>;
1197 def CSR_Win64_RegCall : CalleeSavedRegs<(add CSR_Win64_RegCall_NoSSE,
1198 (sequence "XMM%u", 8, 15))>;
1199 def CSR_SysV64_RegCall_NoSSE : CalleeSavedRegs<(add RBX, RBP,
1200 (sequence "R%u", 12, 15))>;
1201 def CSR_SysV64_RegCall : CalleeSavedRegs<(add CSR_SysV64_RegCall_NoSSE,
1202 (sequence "XMM%u", 8, 15))>;