1 //===- X86CallingConv.td - Calling Conventions X86 32/64 ---*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This describes the calling conventions for the X86-32 and X86-64
13 //===----------------------------------------------------------------------===//
15 /// CCIfSubtarget - Match if the current subtarget has a feature F.
16 class CCIfSubtarget<string F, CCAction A>
17 : CCIf<!strconcat("State.getTarget().getSubtarget<X86Subtarget>().", F), A>;
19 //===----------------------------------------------------------------------===//
20 // Return Value Calling Conventions
21 //===----------------------------------------------------------------------===//
23 // Return-value conventions common to all X86 CC's.
24 def RetCC_X86Common : CallingConv<[
25 // Scalar values are returned in AX first, then DX. For i8, the ABI
26 // requires the values to be in AL and AH, however this code uses AL and DL
27 // instead. This is because using AH for the second register conflicts with
28 // the way LLVM does multiple return values -- a return of {i16,i8} would end
29 // up in AX and AH, which overlap. Front-ends wishing to conform to the ABI
30 // for functions that return two i8 values are currently expected to pack the
31 // values into an i16 (which uses AX, and thus AL:AH).
32 CCIfType<[i8] , CCAssignToReg<[AL, DL]>>,
33 CCIfType<[i16], CCAssignToReg<[AX, DX]>>,
34 CCIfType<[i32], CCAssignToReg<[EAX, EDX]>>,
35 CCIfType<[i64], CCAssignToReg<[RAX, RDX]>>,
37 // Vector types are returned in XMM0 and XMM1, when they fit. XMMM2 and XMM3
38 // can only be used by ABI non-compliant code. If the target doesn't have XMM
39 // registers, it won't have vector types.
40 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
41 CCAssignToReg<[XMM0,XMM1,XMM2,XMM3]>>,
43 // MMX vector types are always returned in MM0. If the target doesn't have
44 // MM0, it doesn't support these vector types.
45 CCIfType<[v8i8, v4i16, v2i32, v1i64, v2f32], CCAssignToReg<[MM0]>>,
47 // Long double types are always returned in ST0 (even with SSE).
48 CCIfType<[f80], CCAssignToReg<[ST0, ST1]>>
51 // X86-32 C return-value convention.
52 def RetCC_X86_32_C : CallingConv<[
53 // The X86-32 calling convention returns FP values in ST0, unless marked
54 // with "inreg" (used here to distinguish one kind of reg from another,
55 // weirdly; this is really the sse-regparm calling convention) in which
56 // case they use XMM0, otherwise it is the same as the common X86 calling
58 CCIfInReg<CCIfSubtarget<"hasSSE2()",
59 CCIfType<[f32, f64], CCAssignToReg<[XMM0,XMM1,XMM2]>>>>,
60 CCIfType<[f32,f64], CCAssignToReg<[ST0, ST1]>>,
61 CCDelegateTo<RetCC_X86Common>
64 // X86-32 FastCC return-value convention.
65 def RetCC_X86_32_Fast : CallingConv<[
66 // The X86-32 fastcc returns 1, 2, or 3 FP values in XMM0-2 if the target has
67 // SSE2, otherwise it is the the C calling conventions.
68 // This can happen when a float, 2 x float, or 3 x float vector is split by
69 // target lowering, and is returned in 1-3 sse regs.
70 CCIfType<[f32], CCIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0,XMM1,XMM2]>>>,
71 CCIfType<[f64], CCIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0,XMM1,XMM2]>>>,
72 CCDelegateTo<RetCC_X86Common>
75 // X86-64 C return-value convention.
76 def RetCC_X86_64_C : CallingConv<[
77 // The X86-64 calling convention always returns FP values in XMM0.
78 CCIfType<[f32], CCAssignToReg<[XMM0, XMM1]>>,
79 CCIfType<[f64], CCAssignToReg<[XMM0, XMM1]>>,
81 // MMX vector types are always returned in XMM0 except for v1i64 which is
82 // returned in RAX. This disagrees with ABI documentation but is bug
83 // compatible with gcc.
84 CCIfType<[v1i64], CCAssignToReg<[RAX]>>,
85 CCIfType<[v8i8, v4i16, v2i32, v2f32], CCAssignToReg<[XMM0, XMM1]>>,
86 CCDelegateTo<RetCC_X86Common>
89 // X86-Win64 C return-value convention.
90 def RetCC_X86_Win64_C : CallingConv<[
91 // The X86-Win64 calling convention always returns __m64 values in RAX.
92 CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToReg<[RAX]>>,
94 // And FP in XMM0 only.
95 CCIfType<[f32], CCAssignToReg<[XMM0]>>,
96 CCIfType<[f64], CCAssignToReg<[XMM0]>>,
98 // Otherwise, everything is the same as 'normal' X86-64 C CC.
99 CCDelegateTo<RetCC_X86_64_C>
103 // This is the root return-value convention for the X86-32 backend.
104 def RetCC_X86_32 : CallingConv<[
105 // If FastCC, use RetCC_X86_32_Fast.
106 CCIfCC<"CallingConv::Fast", CCDelegateTo<RetCC_X86_32_Fast>>,
107 // Otherwise, use RetCC_X86_32_C.
108 CCDelegateTo<RetCC_X86_32_C>
111 // This is the root return-value convention for the X86-64 backend.
112 def RetCC_X86_64 : CallingConv<[
113 // Mingw64 and native Win64 use Win64 CC
114 CCIfSubtarget<"isTargetWin64()", CCDelegateTo<RetCC_X86_Win64_C>>,
116 // Otherwise, drop to normal X86-64 CC
117 CCDelegateTo<RetCC_X86_64_C>
120 // This is the return-value convention used for the entire X86 backend.
121 def RetCC_X86 : CallingConv<[
122 CCIfSubtarget<"is64Bit()", CCDelegateTo<RetCC_X86_64>>,
123 CCDelegateTo<RetCC_X86_32>
126 //===----------------------------------------------------------------------===//
127 // X86-64 Argument Calling Conventions
128 //===----------------------------------------------------------------------===//
130 def CC_X86_64_C : CallingConv<[
131 // Handles byval parameters.
132 CCIfByVal<CCPassByVal<8, 8>>,
134 // Promote i8/i16 arguments to i32.
135 CCIfType<[i8, i16], CCPromoteToType<i32>>,
137 // The 'nest' parameter, if any, is passed in R10.
138 CCIfNest<CCAssignToReg<[R10]>>,
140 // The first 6 integer arguments are passed in integer registers.
141 CCIfType<[i32], CCAssignToReg<[EDI, ESI, EDX, ECX, R8D, R9D]>>,
142 CCIfType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8 , R9 ]>>,
144 // The first 8 FP/Vector arguments are passed in XMM registers.
145 CCIfType<[f32, f64, v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
146 CCIfSubtarget<"hasSSE1()",
147 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7]>>>,
149 // The first 8 MMX (except for v1i64) vector arguments are passed in XMM
150 // registers on Darwin.
151 CCIfType<[v8i8, v4i16, v2i32, v2f32],
152 CCIfSubtarget<"isTargetDarwin()",
153 CCIfSubtarget<"hasSSE2()",
154 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7]>>>>,
156 // The first 8 v1i64 vector arguments are passed in GPRs on Darwin.
158 CCIfSubtarget<"isTargetDarwin()",
159 CCAssignToReg<[RDI, RSI, RDX, RCX, R8]>>>,
161 // Integer/FP values get stored in stack slots that are 8 bytes in size and
162 // 8-byte aligned if there are no more registers to hold them.
163 CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>,
165 // Long doubles get stack slots whose size and alignment depends on the
167 CCIfType<[f80], CCAssignToStack<0, 0>>,
169 // Vectors get 16-byte stack slots that are 16-byte aligned.
170 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToStack<16, 16>>,
172 // __m64 vectors get 8-byte stack slots that are 8-byte aligned.
173 CCIfType<[v8i8, v4i16, v2i32, v1i64, v2f32], CCAssignToStack<8, 8>>
176 // Calling convention used on Win64
177 def CC_X86_Win64_C : CallingConv<[
178 // FIXME: Handle byval stuff.
179 // FIXME: Handle varargs.
181 // Promote i8/i16 arguments to i32.
182 CCIfType<[i8, i16], CCPromoteToType<i32>>,
184 // The 'nest' parameter, if any, is passed in R10.
185 CCIfNest<CCAssignToReg<[R10]>>,
187 // The first 4 integer arguments are passed in integer registers.
188 CCIfType<[i32], CCAssignToRegWithShadow<[ECX , EDX , R8D , R9D ],
189 [XMM0, XMM1, XMM2, XMM3]>>,
190 CCIfType<[i64], CCAssignToRegWithShadow<[RCX , RDX , R8 , R9 ],
191 [XMM0, XMM1, XMM2, XMM3]>>,
193 // The first 4 FP/Vector arguments are passed in XMM registers.
194 CCIfType<[f32, f64, v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
195 CCAssignToRegWithShadow<[XMM0, XMM1, XMM2, XMM3],
196 [RCX , RDX , R8 , R9 ]>>,
198 // The first 4 MMX vector arguments are passed in GPRs.
199 CCIfType<[v8i8, v4i16, v2i32, v1i64, v2f32],
200 CCAssignToRegWithShadow<[RCX , RDX , R8 , R9 ],
201 [XMM0, XMM1, XMM2, XMM3]>>,
203 // Integer/FP values get stored in stack slots that are 8 bytes in size and
204 // 16-byte aligned if there are no more registers to hold them.
205 CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 16>>,
207 // Long doubles get stack slots whose size and alignment depends on the
209 CCIfType<[f80], CCAssignToStack<0, 0>>,
211 // Vectors get 16-byte stack slots that are 16-byte aligned.
212 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToStack<16, 16>>,
214 // __m64 vectors get 8-byte stack slots that are 16-byte aligned.
215 CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToStack<8, 16>>
218 // Tail call convention (fast): One register is reserved for target address,
220 def CC_X86_64_TailCall : CallingConv<[
221 // Handles byval parameters.
222 CCIfByVal<CCPassByVal<8, 8>>,
224 // Promote i8/i16 arguments to i32.
225 CCIfType<[i8, i16], CCPromoteToType<i32>>,
227 // The 'nest' parameter, if any, is passed in R10.
228 CCIfNest<CCAssignToReg<[R10]>>,
230 // The first 6 integer arguments are passed in integer registers.
231 CCIfType<[i32], CCAssignToReg<[EDI, ESI, EDX, ECX, R8D]>>,
232 CCIfType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8]>>,
234 // The first 8 FP/Vector arguments are passed in XMM registers.
235 CCIfType<[f32, f64, v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
236 CCIfSubtarget<"hasSSE1()",
237 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7]>>>,
239 // The first 8 MMX (except for v1i64) vector arguments are passed in XMM
240 // registers on Darwin.
241 CCIfType<[v8i8, v4i16, v2i32, v2f32],
242 CCIfSubtarget<"isTargetDarwin()",
243 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7]>>>,
245 // The first 8 v1i64 vector arguments are passed in GPRs on Darwin.
247 CCIfSubtarget<"isTargetDarwin()",
248 CCAssignToReg<[RDI, RSI, RDX, RCX, R8]>>>,
250 // Integer/FP values get stored in stack slots that are 8 bytes in size and
251 // 8-byte aligned if there are no more registers to hold them.
252 CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>,
254 // Vectors get 16-byte stack slots that are 16-byte aligned.
255 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToStack<16, 16>>,
257 // __m64 vectors get 8-byte stack slots that are 8-byte aligned.
258 CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToStack<8, 8>>
262 //===----------------------------------------------------------------------===//
263 // X86 C Calling Convention
264 //===----------------------------------------------------------------------===//
266 /// CC_X86_32_Common - In all X86-32 calling conventions, extra integers and FP
267 /// values are spilled on the stack, and the first 4 vector values go in XMM
269 def CC_X86_32_Common : CallingConv<[
270 // Handles byval parameters.
271 CCIfByVal<CCPassByVal<4, 4>>,
273 // The first 3 float or double arguments, if marked 'inreg' and if the call
274 // is not a vararg call and if SSE2 is available, are passed in SSE registers.
275 CCIfNotVarArg<CCIfInReg<CCIfType<[f32,f64],
276 CCIfSubtarget<"hasSSE2()",
277 CCAssignToReg<[XMM0,XMM1,XMM2]>>>>>,
279 // The first 3 __m64 (except for v1i64) vector arguments are passed in mmx
280 // registers if the call is not a vararg call.
281 CCIfNotVarArg<CCIfType<[v8i8, v4i16, v2i32, v2f32],
282 CCAssignToReg<[MM0, MM1, MM2]>>>,
284 // Integer/Float values get stored in stack slots that are 4 bytes in
285 // size and 4-byte aligned.
286 CCIfType<[i32, f32], CCAssignToStack<4, 4>>,
288 // Doubles get 8-byte slots that are 4-byte aligned.
289 CCIfType<[f64], CCAssignToStack<8, 4>>,
291 // Long doubles get slots whose size depends on the subtarget.
292 CCIfType<[f80], CCAssignToStack<0, 4>>,
294 // The first 4 SSE vector arguments are passed in XMM registers.
295 CCIfNotVarArg<CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
296 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3]>>>,
298 // Other SSE vectors get 16-byte stack slots that are 16-byte aligned.
299 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToStack<16, 16>>,
301 // __m64 vectors get 8-byte stack slots that are 4-byte aligned. They are
302 // passed in the parameter area.
303 CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToStack<8, 4>>]>;
305 def CC_X86_32_C : CallingConv<[
306 // Promote i8/i16 arguments to i32.
307 CCIfType<[i8, i16], CCPromoteToType<i32>>,
309 // The 'nest' parameter, if any, is passed in ECX.
310 CCIfNest<CCAssignToReg<[ECX]>>,
312 // The first 3 integer arguments, if marked 'inreg' and if the call is not
313 // a vararg call, are passed in integer registers.
314 CCIfNotVarArg<CCIfInReg<CCIfType<[i32], CCAssignToReg<[EAX, EDX, ECX]>>>>,
316 // Otherwise, same as everything else.
317 CCDelegateTo<CC_X86_32_Common>
320 def CC_X86_32_FastCall : CallingConv<[
321 // Promote i8/i16 arguments to i32.
322 CCIfType<[i8, i16], CCPromoteToType<i32>>,
324 // The 'nest' parameter, if any, is passed in EAX.
325 CCIfNest<CCAssignToReg<[EAX]>>,
327 // The first 2 integer arguments are passed in ECX/EDX
328 CCIfType<[i32], CCAssignToReg<[ECX, EDX]>>,
330 // Otherwise, same as everything else.
331 CCDelegateTo<CC_X86_32_Common>
334 def CC_X86_32_FastCC : CallingConv<[
335 // Handles byval parameters. Note that we can't rely on the delegation
336 // to CC_X86_32_Common for this because that happens after code that
337 // puts arguments in registers.
338 CCIfByVal<CCPassByVal<4, 4>>,
340 // Promote i8/i16 arguments to i32.
341 CCIfType<[i8, i16], CCPromoteToType<i32>>,
343 // The 'nest' parameter, if any, is passed in EAX.
344 CCIfNest<CCAssignToReg<[EAX]>>,
346 // The first 2 integer arguments are passed in ECX/EDX
347 CCIfType<[i32], CCAssignToReg<[ECX, EDX]>>,
349 // The first 3 float or double arguments, if the call is not a vararg
350 // call and if SSE2 is available, are passed in SSE registers.
351 CCIfNotVarArg<CCIfType<[f32,f64],
352 CCIfSubtarget<"hasSSE2()",
353 CCAssignToReg<[XMM0,XMM1,XMM2]>>>>,
355 // Doubles get 8-byte slots that are 8-byte aligned.
356 CCIfType<[f64], CCAssignToStack<8, 8>>,
358 // Otherwise, same as everything else.
359 CCDelegateTo<CC_X86_32_Common>