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], CCBitConvertToType<i64>>,
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 v1i64 vector arguments are passed in GPRs on Darwin.
142 CCIfSubtarget<"isTargetDarwin()",
143 CCBitConvertToType<i64>>>,
145 // The first 6 integer arguments are passed in integer registers.
146 CCIfType<[i32], CCAssignToReg<[EDI, ESI, EDX, ECX, R8D, R9D]>>,
147 CCIfType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8 , R9 ]>>,
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 CCPromoteToType<v2i64>>>>,
156 // The first 8 FP/Vector arguments are passed in XMM registers.
157 CCIfType<[f32, f64, v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
158 CCIfSubtarget<"hasSSE1()",
159 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7]>>>,
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 // 128 bit vectors are passed by pointer
188 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCPassIndirect<i64>>,
190 // The first 4 MMX vector arguments are passed in GPRs.
191 CCIfType<[v8i8, v4i16, v2i32, v1i64, v2f32],
192 CCBitConvertToType<i64>>,
194 // The first 4 integer arguments are passed in integer registers.
195 CCIfType<[i32], CCAssignToRegWithShadow<[ECX , EDX , R8D , R9D ],
196 [XMM0, XMM1, XMM2, XMM3]>>,
197 CCIfType<[i64], CCAssignToRegWithShadow<[RCX , RDX , R8 , R9 ],
198 [XMM0, XMM1, XMM2, XMM3]>>,
200 // The first 4 FP/Vector arguments are passed in XMM registers.
201 CCIfType<[f32, f64, v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
202 CCAssignToRegWithShadow<[XMM0, XMM1, XMM2, XMM3],
203 [RCX , RDX , R8 , R9 ]>>,
205 // Integer/FP values get stored in stack slots that are 8 bytes in size and
206 // 8-byte aligned if there are no more registers to hold them.
207 CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>,
209 // Long doubles get stack slots whose size and alignment depends on the
211 CCIfType<[f80], CCAssignToStack<0, 0>>,
213 // __m64 vectors get 8-byte stack slots that are 8-byte aligned.
214 CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToStack<8, 8>>
217 //===----------------------------------------------------------------------===//
218 // X86 C Calling Convention
219 //===----------------------------------------------------------------------===//
221 /// CC_X86_32_Common - In all X86-32 calling conventions, extra integers and FP
222 /// values are spilled on the stack, and the first 4 vector values go in XMM
224 def CC_X86_32_Common : CallingConv<[
225 // Handles byval parameters.
226 CCIfByVal<CCPassByVal<4, 4>>,
228 // The first 3 float or double arguments, if marked 'inreg' and if the call
229 // is not a vararg call and if SSE2 is available, are passed in SSE registers.
230 CCIfNotVarArg<CCIfInReg<CCIfType<[f32,f64],
231 CCIfSubtarget<"hasSSE2()",
232 CCAssignToReg<[XMM0,XMM1,XMM2]>>>>>,
234 // The first 3 __m64 (except for v1i64) vector arguments are passed in mmx
235 // registers if the call is not a vararg call.
236 CCIfNotVarArg<CCIfType<[v8i8, v4i16, v2i32, v2f32],
237 CCAssignToReg<[MM0, MM1, MM2]>>>,
239 // Integer/Float values get stored in stack slots that are 4 bytes in
240 // size and 4-byte aligned.
241 CCIfType<[i32, f32], CCAssignToStack<4, 4>>,
243 // Doubles get 8-byte slots that are 4-byte aligned.
244 CCIfType<[f64], CCAssignToStack<8, 4>>,
246 // Long doubles get slots whose size depends on the subtarget.
247 CCIfType<[f80], CCAssignToStack<0, 4>>,
249 // The first 4 SSE vector arguments are passed in XMM registers.
250 CCIfNotVarArg<CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
251 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3]>>>,
253 // Other SSE vectors get 16-byte stack slots that are 16-byte aligned.
254 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToStack<16, 16>>,
256 // __m64 vectors get 8-byte stack slots that are 4-byte aligned. They are
257 // passed in the parameter area.
258 CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToStack<8, 4>>]>;
260 def CC_X86_32_C : CallingConv<[
261 // Promote i8/i16 arguments to i32.
262 CCIfType<[i8, i16], CCPromoteToType<i32>>,
264 // The 'nest' parameter, if any, is passed in ECX.
265 CCIfNest<CCAssignToReg<[ECX]>>,
267 // The first 3 integer arguments, if marked 'inreg' and if the call is not
268 // a vararg call, are passed in integer registers.
269 CCIfNotVarArg<CCIfInReg<CCIfType<[i32], CCAssignToReg<[EAX, EDX, ECX]>>>>,
271 // Otherwise, same as everything else.
272 CCDelegateTo<CC_X86_32_Common>
275 def CC_X86_32_FastCall : CallingConv<[
276 // Promote i8/i16 arguments to i32.
277 CCIfType<[i8, i16], CCPromoteToType<i32>>,
279 // The 'nest' parameter, if any, is passed in EAX.
280 CCIfNest<CCAssignToReg<[EAX]>>,
282 // The first 2 integer arguments are passed in ECX/EDX
283 CCIfType<[i32], CCAssignToReg<[ECX, EDX]>>,
285 // Otherwise, same as everything else.
286 CCDelegateTo<CC_X86_32_Common>
289 def CC_X86_32_FastCC : CallingConv<[
290 // Handles byval parameters. Note that we can't rely on the delegation
291 // to CC_X86_32_Common for this because that happens after code that
292 // puts arguments in registers.
293 CCIfByVal<CCPassByVal<4, 4>>,
295 // Promote i8/i16 arguments to i32.
296 CCIfType<[i8, i16], CCPromoteToType<i32>>,
298 // The 'nest' parameter, if any, is passed in EAX.
299 CCIfNest<CCAssignToReg<[EAX]>>,
301 // The first 2 integer arguments are passed in ECX/EDX
302 CCIfType<[i32], CCAssignToReg<[ECX, EDX]>>,
304 // The first 3 float or double arguments, if the call is not a vararg
305 // call and if SSE2 is available, are passed in SSE registers.
306 CCIfNotVarArg<CCIfType<[f32,f64],
307 CCIfSubtarget<"hasSSE2()",
308 CCAssignToReg<[XMM0,XMM1,XMM2]>>>>,
310 // Doubles get 8-byte slots that are 8-byte aligned.
311 CCIfType<[f64], CCAssignToStack<8, 8>>,
313 // Otherwise, same as everything else.
314 CCDelegateTo<CC_X86_32_Common>