blob: 310dbb7671bde612818aaae1d8d6a172135f9413 [file] [log] [blame]
Arnold Schwaighofer48abc5c2007-10-12 21:30:57 +00001//===- X86CallingConv.td - Calling Conventions X86 32/64 ---*- tablegen -*-===//
Chris Lattner31c8a6d2007-02-26 18:17:14 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner31c8a6d2007-02-26 18:17:14 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This describes the calling conventions for the X86-32 and X86-64
11// architectures.
12//
13//===----------------------------------------------------------------------===//
14
Chris Lattner370bdda2007-02-28 05:30:29 +000015/// CCIfSubtarget - Match if the current subtarget has a feature F.
16class CCIfSubtarget<string F, CCAction A>
17 : CCIf<!strconcat("State.getTarget().getSubtarget<X86Subtarget>().", F), A>;
Chris Lattner3d559102007-02-28 04:51:41 +000018
Chris Lattner31c8a6d2007-02-26 18:17:14 +000019//===----------------------------------------------------------------------===//
20// Return Value Calling Conventions
21//===----------------------------------------------------------------------===//
22
Chris Lattnerd50110d2007-02-27 05:51:05 +000023// Return-value conventions common to all X86 CC's.
Chris Lattner31c8a6d2007-02-26 18:17:14 +000024def RetCC_X86Common : CallingConv<[
25 // Scalar values are returned in AX first, then DX.
Chris Lattner370bdda2007-02-28 05:30:29 +000026 CCIfType<[i8] , CCAssignToReg<[AL]>>,
27 CCIfType<[i16], CCAssignToReg<[AX]>>,
28 CCIfType<[i32], CCAssignToReg<[EAX, EDX]>>,
29 CCIfType<[i64], CCAssignToReg<[RAX, RDX]>>,
Chris Lattner31c8a6d2007-02-26 18:17:14 +000030
Dan Gohman1866f6e2007-07-02 16:21:53 +000031 // Vector types are returned in XMM0 and XMM1, when they fit. If the target
32 // doesn't have XMM registers, it won't have vector types.
33 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
34 CCAssignToReg<[XMM0,XMM1]>>,
Bill Wendlinge2501b32007-03-30 00:35:22 +000035
36 // MMX vector types are always returned in MM0. If the target doesn't have
37 // MM0, it doesn't support these vector types.
Dale Johannesen6a308112007-08-06 21:31:06 +000038 CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToReg<[MM0]>>,
39
40 // Long double types are always returned in ST0 (even with SSE).
Chris Lattner03535262008-03-21 05:57:20 +000041 CCIfType<[f80], CCAssignToReg<[ST0, ST1]>>
Chris Lattner31c8a6d2007-02-26 18:17:14 +000042]>;
43
Chris Lattnerd50110d2007-02-27 05:51:05 +000044// X86-32 C return-value convention.
Chris Lattner31c8a6d2007-02-26 18:17:14 +000045def RetCC_X86_32_C : CallingConv<[
46 // The X86-32 calling convention returns FP values in ST0, otherwise it is the
47 // same as the common X86 calling conv.
Chris Lattner03535262008-03-21 05:57:20 +000048 CCIfType<[f32], CCAssignToReg<[ST0, ST1]>>,
49 CCIfType<[f64], CCAssignToReg<[ST0, ST1]>>,
Chris Lattner31c8a6d2007-02-26 18:17:14 +000050 CCDelegateTo<RetCC_X86Common>
51]>;
52
Chris Lattnerd50110d2007-02-27 05:51:05 +000053// X86-32 FastCC return-value convention.
Chris Lattner31c8a6d2007-02-26 18:17:14 +000054def RetCC_X86_32_Fast : CallingConv<[
Nate Begemand73ab882007-11-27 19:28:48 +000055 // The X86-32 fastcc returns 1, 2, or 3 FP values in XMM0-2 if the target has
56 // SSE2, otherwise it is the the C calling conventions.
57 // This can happen when a float, 2 x float, or 3 x float vector is split by
58 // target lowering, and is returned in 1-3 sse regs.
59 CCIfType<[f32], CCIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0,XMM1,XMM2]>>>,
60 CCIfType<[f64], CCIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0,XMM1,XMM2]>>>,
Chris Lattner31c8a6d2007-02-26 18:17:14 +000061 CCDelegateTo<RetCC_X86Common>
62]>;
63
Dale Johannesene672af12008-02-05 20:46:33 +000064// X86-32 SSEregparm return-value convention.
65def RetCC_X86_32_SSE : CallingConv<[
66 // The X86-32 sseregparm calling convention returns FP values in XMM0 if the
67 // target has SSE2, otherwise it is the C calling convention.
68 CCIfType<[f32], CCIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0]>>>,
69 CCIfType<[f64], CCIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0]>>>,
70 CCDelegateTo<RetCC_X86Common>
71]>;
72
Chris Lattnerd50110d2007-02-27 05:51:05 +000073// X86-64 C return-value convention.
Chris Lattner31c8a6d2007-02-26 18:17:14 +000074def RetCC_X86_64_C : CallingConv<[
75 // The X86-64 calling convention always returns FP values in XMM0.
Chris Lattner370bdda2007-02-28 05:30:29 +000076 CCIfType<[f32], CCAssignToReg<[XMM0]>>,
77 CCIfType<[f64], CCAssignToReg<[XMM0]>>,
Chris Lattner31c8a6d2007-02-26 18:17:14 +000078 CCDelegateTo<RetCC_X86Common>
79]>;
80
Anton Korobeynikov8f88cb02008-03-22 20:37:30 +000081// X86-Win64 C return-value convention.
82def RetCC_X86_Win64_C : CallingConv<[
Anton Korobeynikov82818eb2008-03-23 20:32:06 +000083 // The X86-Win64 calling convention always returns __m64 values in RAX.
Anton Korobeynikov8f88cb02008-03-22 20:37:30 +000084 CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToReg<[RAX]>>,
85
Anton Korobeynikov82818eb2008-03-23 20:32:06 +000086 // Otherwise, everything is the same as 'normal' X86-64 C CC.
Anton Korobeynikov8f88cb02008-03-22 20:37:30 +000087 CCDelegateTo<RetCC_X86_64_C>
88]>;
89
90
Chris Lattnerd50110d2007-02-27 05:51:05 +000091// This is the root return-value convention for the X86-32 backend.
92def RetCC_X86_32 : CallingConv<[
93 // If FastCC, use RetCC_X86_32_Fast.
Chris Lattner370bdda2007-02-28 05:30:29 +000094 CCIfCC<"CallingConv::Fast", CCDelegateTo<RetCC_X86_32_Fast>>,
Dale Johannesene672af12008-02-05 20:46:33 +000095 // If SSECC, use RetCC_X86_32_SSE.
96 CCIfCC<"CallingConv::X86_SSECall", CCDelegateTo<RetCC_X86_32_SSE>>,
Chris Lattnerd50110d2007-02-27 05:51:05 +000097 // Otherwise, use RetCC_X86_32_C.
98 CCDelegateTo<RetCC_X86_32_C>
99]>;
100
101// This is the root return-value convention for the X86-64 backend.
102def RetCC_X86_64 : CallingConv<[
Anton Korobeynikov8f88cb02008-03-22 20:37:30 +0000103 // Mingw64 and native Win64 use Win64 CC
Anton Korobeynikov1a979d92008-03-22 20:57:27 +0000104 CCIfSubtarget<"isTargetWin64()", CCDelegateTo<RetCC_X86_Win64_C>>,
Anton Korobeynikov8f88cb02008-03-22 20:37:30 +0000105
106 // Otherwise, drop to normal X86-64 CC
Chris Lattnerd50110d2007-02-27 05:51:05 +0000107 CCDelegateTo<RetCC_X86_64_C>
108]>;
109
Chris Lattnerd637a8b2007-02-27 06:59:52 +0000110// This is the return-value convention used for the entire X86 backend.
111def RetCC_X86 : CallingConv<[
Chris Lattner370bdda2007-02-28 05:30:29 +0000112 CCIfSubtarget<"is64Bit()", CCDelegateTo<RetCC_X86_64>>,
Chris Lattnerd637a8b2007-02-27 06:59:52 +0000113 CCDelegateTo<RetCC_X86_32>
114]>;
Chris Lattnerd50110d2007-02-27 05:51:05 +0000115
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000116//===----------------------------------------------------------------------===//
Chris Lattner370bdda2007-02-28 05:30:29 +0000117// X86-64 Argument Calling Conventions
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000118//===----------------------------------------------------------------------===//
119
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000120def CC_X86_64_C : CallingConv<[
Evan Chengbdfd5ef2008-01-15 03:15:41 +0000121 // Handles byval parameters.
Evan Cheng6bfa8a12008-01-15 03:34:58 +0000122 CCIfByVal<CCPassByVal<8, 8>>,
Evan Chengbdfd5ef2008-01-15 03:15:41 +0000123
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000124 // Promote i8/i16 arguments to i32.
Chris Lattner370bdda2007-02-28 05:30:29 +0000125 CCIfType<[i8, i16], CCPromoteToType<i32>>,
Duncan Sands4bdad512008-01-19 16:42:10 +0000126
127 // The 'nest' parameter, if any, is passed in R10.
128 CCIfNest<CCAssignToReg<[R10]>>,
129
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000130 // The first 6 integer arguments are passed in integer registers.
Chris Lattner370bdda2007-02-28 05:30:29 +0000131 CCIfType<[i32], CCAssignToReg<[EDI, ESI, EDX, ECX, R8D, R9D]>>,
132 CCIfType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8 , R9 ]>>,
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000133
134 // The first 8 FP/Vector arguments are passed in XMM registers.
Chris Lattner370bdda2007-02-28 05:30:29 +0000135 CCIfType<[f32, f64, v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000136 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7]>>,
137
Bill Wendling577c7d92007-03-31 09:36:12 +0000138 // The first 8 MMX vector arguments are passed in GPRs.
Bill Wendlingdb5c9932007-03-31 01:03:53 +0000139 CCIfType<[v8i8, v4i16, v2i32, v1i64],
140 CCAssignToReg<[RDI, RSI, RDX, RCX, R8 , R9 ]>>,
141
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000142 // Integer/FP values get stored in stack slots that are 8 bytes in size and
143 // 8-byte aligned if there are no more registers to hold them.
Chris Lattner370bdda2007-02-28 05:30:29 +0000144 CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>,
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000145
Dale Johannesene3ef7442007-11-10 22:07:15 +0000146 // Long doubles get stack slots whose size and alignment depends on the
147 // subtarget.
Duncan Sands87b665d2007-11-14 08:29:13 +0000148 CCIfType<[f80], CCAssignToStack<0, 0>>,
Dale Johannesene3ef7442007-11-10 22:07:15 +0000149
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000150 // Vectors get 16-byte stack slots that are 16-byte aligned.
Dale Johannesene3ef7442007-11-10 22:07:15 +0000151 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToStack<16, 16>>,
Bill Wendlinge2501b32007-03-30 00:35:22 +0000152
153 // __m64 vectors get 8-byte stack slots that are 8-byte aligned.
154 CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToStack<8, 8>>
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000155]>;
156
Anton Korobeynikov8f88cb02008-03-22 20:37:30 +0000157// Calling convention used on Win64
158def CC_X86_Win64_C : CallingConv<[
Anton Korobeynikov82818eb2008-03-23 20:32:06 +0000159 // FIXME: Handle byval stuff.
160 // FIXME: Handle fp80.
161 // FIXME: Handle shadowed arguments.
162 // FIXME: Handle nested functions.
Anton Korobeynikov8f88cb02008-03-22 20:37:30 +0000163
164 // Promote i8/i16 arguments to i32.
165 CCIfType<[i8, i16], CCPromoteToType<i32>>,
166
167 // The first 4 integer arguments are passed in integer registers.
168 CCIfType<[i32], CCAssignToReg<[ECX, EDX, R8D, R9D]>>,
169 CCIfType<[i64], CCAssignToReg<[RCX, RDX, R8 , R9 ]>>,
170
171 // The first 4 FP/Vector arguments are passed in XMM registers.
172 CCIfType<[f32, f64, v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
173 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3]>>,
174
175 // The first 4 MMX vector arguments are passed in GPRs.
176 CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToReg<[RCX, RDX, R8, R9]>>,
177
178 // Integer/FP values get stored in stack slots that are 8 bytes in size and
179 // 16-byte aligned if there are no more registers to hold them.
180 CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 16>>,
181
182 // Vectors get 16-byte stack slots that are 16-byte aligned.
183 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToStack<16, 16>>,
184
185 // __m64 vectors get 8-byte stack slots that are 16-byte aligned.
186 CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToStack<8, 16>>
187]>;
188
Arnold Schwaighofer48abc5c2007-10-12 21:30:57 +0000189// Tail call convention (fast): One register is reserved for target address,
Arnold Schwaighoferc85e1712007-10-11 19:40:01 +0000190// namely R9
191def CC_X86_64_TailCall : CallingConv<[
Evan Chengbdfd5ef2008-01-15 03:15:41 +0000192 // Handles byval parameters.
Evan Cheng6bfa8a12008-01-15 03:34:58 +0000193 CCIfByVal<CCPassByVal<8, 8>>,
Evan Chengbdfd5ef2008-01-15 03:15:41 +0000194
Arnold Schwaighoferc85e1712007-10-11 19:40:01 +0000195 // Promote i8/i16 arguments to i32.
196 CCIfType<[i8, i16], CCPromoteToType<i32>>,
Duncan Sands4bdad512008-01-19 16:42:10 +0000197
198 // The 'nest' parameter, if any, is passed in R10.
199 CCIfNest<CCAssignToReg<[R10]>>,
200
Arnold Schwaighoferc85e1712007-10-11 19:40:01 +0000201 // The first 6 integer arguments are passed in integer registers.
202 CCIfType<[i32], CCAssignToReg<[EDI, ESI, EDX, ECX, R8D]>>,
203 CCIfType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8]>>,
204
205 // The first 8 FP/Vector arguments are passed in XMM registers.
206 CCIfType<[f32, f64, v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
207 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7]>>,
208
209 // The first 8 MMX vector arguments are passed in GPRs.
210 CCIfType<[v8i8, v4i16, v2i32, v1i64],
211 CCAssignToReg<[RDI, RSI, RDX, RCX, R8]>>,
212
Arnold Schwaighoferc85e1712007-10-11 19:40:01 +0000213 // Integer/FP values get stored in stack slots that are 8 bytes in size and
214 // 8-byte aligned if there are no more registers to hold them.
215 CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>,
216
217 // Vectors get 16-byte stack slots that are 16-byte aligned.
218 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToStack<16, 16>>,
219
220 // __m64 vectors get 8-byte stack slots that are 8-byte aligned.
221 CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToStack<8, 8>>
222]>;
223
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000224
Chris Lattner423c5f42007-02-28 05:31:48 +0000225//===----------------------------------------------------------------------===//
226// X86 C Calling Convention
227//===----------------------------------------------------------------------===//
228
Chris Lattner011bcc82007-02-28 06:20:01 +0000229/// CC_X86_32_Common - In all X86-32 calling conventions, extra integers and FP
230/// values are spilled on the stack, and the first 4 vector values go in XMM
231/// regs.
232def CC_X86_32_Common : CallingConv<[
Evan Chengbdfd5ef2008-01-15 03:15:41 +0000233 // Handles byval parameters.
Evan Cheng6bfa8a12008-01-15 03:34:58 +0000234 CCIfByVal<CCPassByVal<4, 4>>,
Evan Chengbdfd5ef2008-01-15 03:15:41 +0000235
Dale Johannesene672af12008-02-05 20:46:33 +0000236 // The first 3 float or double arguments, if marked 'inreg' and if the call
237 // is not a vararg call and if SSE2 is available, are passed in SSE registers.
238 CCIfNotVarArg<CCIfInReg<CCIfType<[f32,f64], CCIfSubtarget<"hasSSE2()",
239 CCAssignToReg<[XMM0,XMM1,XMM2]>>>>>,
240
Chris Lattner011bcc82007-02-28 06:20:01 +0000241 // Integer/Float values get stored in stack slots that are 4 bytes in
242 // size and 4-byte aligned.
243 CCIfType<[i32, f32], CCAssignToStack<4, 4>>,
244
245 // Doubles get 8-byte slots that are 4-byte aligned.
246 CCIfType<[f64], CCAssignToStack<8, 4>>,
Dale Johannesen6a308112007-08-06 21:31:06 +0000247
Duncan Sands30d157512008-01-07 16:36:38 +0000248 // Long doubles get slots whose size depends on the subtarget.
249 CCIfType<[f80], CCAssignToStack<0, 4>>,
Dale Johannesen6a308112007-08-06 21:31:06 +0000250
Dale Johannesen3edd6dc2008-02-22 17:47:28 +0000251 // The first 4 SSE vector arguments are passed in XMM registers.
Evan Cheng2cbdd272008-01-22 23:26:53 +0000252 CCIfNotVarArg<CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
253 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3]>>>,
Chris Lattner011bcc82007-02-28 06:20:01 +0000254
Dale Johannesen3edd6dc2008-02-22 17:47:28 +0000255 // Other SSE vectors get 16-byte stack slots that are 16-byte aligned.
Bill Wendlinge2501b32007-03-30 00:35:22 +0000256 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToStack<16, 16>>,
257
Dale Johannesen3edd6dc2008-02-22 17:47:28 +0000258 // __m64 vectors get 8-byte stack slots that are 4-byte aligned. They are
Bill Wendlinge2501b32007-03-30 00:35:22 +0000259 // passed in the parameter area.
Dale Johannesen3edd6dc2008-02-22 17:47:28 +0000260 CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToStack<8, 4>>
Chris Lattner011bcc82007-02-28 06:20:01 +0000261]>;
262
Chris Lattner423c5f42007-02-28 05:31:48 +0000263def CC_X86_32_C : CallingConv<[
264 // Promote i8/i16 arguments to i32.
265 CCIfType<[i8, i16], CCPromoteToType<i32>>,
Duncan Sandsb116fac2007-07-27 20:02:49 +0000266
267 // The 'nest' parameter, if any, is passed in ECX.
268 CCIfNest<CCAssignToReg<[ECX]>>,
269
Chris Lattner52387be2007-06-19 00:13:10 +0000270 // The first 3 integer arguments, if marked 'inreg' and if the call is not
271 // a vararg call, are passed in integer registers.
272 CCIfNotVarArg<CCIfInReg<CCIfType<[i32], CCAssignToReg<[EAX, EDX, ECX]>>>>,
Duncan Sandsb116fac2007-07-27 20:02:49 +0000273
Chris Lattner011bcc82007-02-28 06:20:01 +0000274 // Otherwise, same as everything else.
275 CCDelegateTo<CC_X86_32_Common>
Chris Lattner423c5f42007-02-28 05:31:48 +0000276]>;
277
Arnold Schwaighofer48abc5c2007-10-12 21:30:57 +0000278/// Same as C calling convention except for non-free ECX which is used for storing
279/// a potential pointer to the tail called function.
Arnold Schwaighoferc85e1712007-10-11 19:40:01 +0000280def CC_X86_32_TailCall : CallingConv<[
281 // Promote i8/i16 arguments to i32.
282 CCIfType<[i8, i16], CCPromoteToType<i32>>,
283
Duncan Sands7fef59f2007-10-13 07:38:37 +0000284 // Nested function trampolines are currently not supported by fastcc.
Arnold Schwaighofer48abc5c2007-10-12 21:30:57 +0000285
Arnold Schwaighoferc85e1712007-10-11 19:40:01 +0000286 // The first 3 integer arguments, if marked 'inreg' and if the call is not
287 // a vararg call, are passed in integer registers.
288 CCIfNotVarArg<CCIfInReg<CCIfType<[i32], CCAssignToReg<[EAX, EDX]>>>>,
289
290 // Otherwise, same as everything else.
291 CCDelegateTo<CC_X86_32_Common>
292]>;
Chris Lattner423c5f42007-02-28 05:31:48 +0000293
Chris Lattner011bcc82007-02-28 06:20:01 +0000294def CC_X86_32_FastCall : CallingConv<[
295 // Promote i8/i16 arguments to i32.
296 CCIfType<[i8, i16], CCPromoteToType<i32>>,
Duncan Sandsb116fac2007-07-27 20:02:49 +0000297
298 // The 'nest' parameter, if any, is passed in EAX.
299 CCIfNest<CCAssignToReg<[EAX]>>,
300
Chris Lattner011bcc82007-02-28 06:20:01 +0000301 // The first 2 integer arguments are passed in ECX/EDX
Chris Lattner70500802007-02-28 18:35:11 +0000302 CCIfType<[i32], CCAssignToReg<[ECX, EDX]>>,
Duncan Sandsb116fac2007-07-27 20:02:49 +0000303
Chris Lattner011bcc82007-02-28 06:20:01 +0000304 // Otherwise, same as everything else.
305 CCDelegateTo<CC_X86_32_Common>
306]>;