blob: b240742f17040c6b8f9c718973c3833cd2255e38 [file] [log] [blame]
Jia Liu31d157a2012-02-18 12:03:15 +00001//===-- X86CallingConv.td - Calling Conventions X86 32/64 --*- tablegen -*-===//
2//
Chris Lattner31c8a6d2007-02-26 18:17:14 +00003// 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.
Jia Liu31d157a2012-02-18 12:03:15 +00007//
Chris Lattner31c8a6d2007-02-26 18:17:14 +00008//===----------------------------------------------------------------------===//
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<[
Dan Gohmana96dc142009-03-24 01:04:34 +000025 // 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]>>,
Dan Gohman719e64e2008-04-09 17:53:38 +000033 CCIfType<[i16], CCAssignToReg<[AX, DX]>>,
Chris Lattner370bdda2007-02-28 05:30:29 +000034 CCIfType<[i32], CCAssignToReg<[EAX, EDX]>>,
35 CCIfType<[i64], CCAssignToReg<[RAX, RDX]>>,
Bruno Cardoso Lopesac098352010-08-05 23:35:51 +000036
37 // Vector types are returned in XMM0 and XMM1, when they fit. XMM2 and XMM3
Mon P Wang07239f12008-11-20 07:48:19 +000038 // can only be used by ABI non-compliant code. If the target doesn't have XMM
39 // registers, it won't have vector types.
Dan Gohman1866f6e2007-07-02 16:21:53 +000040 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
Mon P Wang07239f12008-11-20 07:48:19 +000041 CCAssignToReg<[XMM0,XMM1,XMM2,XMM3]>>,
Bill Wendlinge2501b32007-03-30 00:35:22 +000042
Bruno Cardoso Lopesac098352010-08-05 23:35:51 +000043 // 256-bit vectors are returned in YMM0 and XMM1, when they fit. YMM2 and YMM3
44 // can only be used by ABI non-compliant code. This vector type is only
45 // supported while using the AVX target feature.
46 CCIfType<[v32i8, v16i16, v8i32, v4i64, v8f32, v4f64],
Eli Friedmanadebeea2011-07-01 21:33:28 +000047 CCAssignToReg<[YMM0,YMM1,YMM2,YMM3]>>,
Bruno Cardoso Lopesac098352010-08-05 23:35:51 +000048
Bill Wendlinge2501b32007-03-30 00:35:22 +000049 // MMX vector types are always returned in MM0. If the target doesn't have
50 // MM0, it doesn't support these vector types.
Eli Friedmanadebeea2011-07-01 21:33:28 +000051 CCIfType<[x86mmx], CCAssignToReg<[MM0]>>,
Dale Johannesen6a308112007-08-06 21:31:06 +000052
53 // Long double types are always returned in ST0 (even with SSE).
Chris Lattner03535262008-03-21 05:57:20 +000054 CCIfType<[f80], CCAssignToReg<[ST0, ST1]>>
Chris Lattner31c8a6d2007-02-26 18:17:14 +000055]>;
56
Chris Lattnerd50110d2007-02-27 05:51:05 +000057// X86-32 C return-value convention.
Chris Lattner31c8a6d2007-02-26 18:17:14 +000058def RetCC_X86_32_C : CallingConv<[
Dale Johannesenc9c6da62008-09-25 20:47:45 +000059 // The X86-32 calling convention returns FP values in ST0, unless marked
60 // with "inreg" (used here to distinguish one kind of reg from another,
61 // weirdly; this is really the sse-regparm calling convention) in which
62 // case they use XMM0, otherwise it is the same as the common X86 calling
63 // conv.
Craig Topper1accb7e2012-01-10 06:54:16 +000064 CCIfInReg<CCIfSubtarget<"hasSSE2()",
Dale Johannesenc9c6da62008-09-25 20:47:45 +000065 CCIfType<[f32, f64], CCAssignToReg<[XMM0,XMM1,XMM2]>>>>,
66 CCIfType<[f32,f64], CCAssignToReg<[ST0, ST1]>>,
Chris Lattner31c8a6d2007-02-26 18:17:14 +000067 CCDelegateTo<RetCC_X86Common>
68]>;
69
Chris Lattnerd50110d2007-02-27 05:51:05 +000070// X86-32 FastCC return-value convention.
Chris Lattner31c8a6d2007-02-26 18:17:14 +000071def RetCC_X86_32_Fast : CallingConv<[
Nate Begemand73ab882007-11-27 19:28:48 +000072 // The X86-32 fastcc returns 1, 2, or 3 FP values in XMM0-2 if the target has
Kenneth Uildriks76df3f32009-12-15 03:27:52 +000073 // SSE2.
Nate Begemand73ab882007-11-27 19:28:48 +000074 // This can happen when a float, 2 x float, or 3 x float vector is split by
75 // target lowering, and is returned in 1-3 sse regs.
Craig Topper1accb7e2012-01-10 06:54:16 +000076 CCIfType<[f32], CCIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0,XMM1,XMM2]>>>,
77 CCIfType<[f64], CCIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0,XMM1,XMM2]>>>,
Kenneth Uildriks76df3f32009-12-15 03:27:52 +000078
79 // For integers, ECX can be used as an extra return register
80 CCIfType<[i8], CCAssignToReg<[AL, DL, CL]>>,
81 CCIfType<[i16], CCAssignToReg<[AX, DX, CX]>>,
82 CCIfType<[i32], CCAssignToReg<[EAX, EDX, ECX]>>,
83
84 // Otherwise, it is the same as the common X86 calling convention.
Chris Lattner31c8a6d2007-02-26 18:17:14 +000085 CCDelegateTo<RetCC_X86Common>
86]>;
87
Chris Lattnerd50110d2007-02-27 05:51:05 +000088// X86-64 C return-value convention.
Chris Lattner31c8a6d2007-02-26 18:17:14 +000089def RetCC_X86_64_C : CallingConv<[
90 // The X86-64 calling convention always returns FP values in XMM0.
Dan Gohmanc2ffd4b2008-04-09 17:54:37 +000091 CCIfType<[f32], CCAssignToReg<[XMM0, XMM1]>>,
92 CCIfType<[f64], CCAssignToReg<[XMM0, XMM1]>>,
Dale Johannesena68f9012008-06-24 22:01:44 +000093
Eli Friedmanadebeea2011-07-01 21:33:28 +000094 // MMX vector types are always returned in XMM0.
Dale Johannesen0488fb62010-09-30 23:57:10 +000095 CCIfType<[x86mmx], CCAssignToReg<[XMM0, XMM1]>>,
Chris Lattner31c8a6d2007-02-26 18:17:14 +000096 CCDelegateTo<RetCC_X86Common>
97]>;
98
Anton Korobeynikov8f88cb02008-03-22 20:37:30 +000099// X86-Win64 C return-value convention.
100def RetCC_X86_Win64_C : CallingConv<[
Anton Korobeynikov82818eb2008-03-23 20:32:06 +0000101 // The X86-Win64 calling convention always returns __m64 values in RAX.
Eli Friedmanadebeea2011-07-01 21:33:28 +0000102 CCIfType<[x86mmx], CCBitConvertToType<i64>>,
Anton Korobeynikov2810d672008-04-28 07:40:07 +0000103
Anton Korobeynikov82818eb2008-03-23 20:32:06 +0000104 // Otherwise, everything is the same as 'normal' X86-64 C CC.
Anton Korobeynikov8f88cb02008-03-22 20:37:30 +0000105 CCDelegateTo<RetCC_X86_64_C>
106]>;
107
108
Chris Lattnerd50110d2007-02-27 05:51:05 +0000109// This is the root return-value convention for the X86-32 backend.
110def RetCC_X86_32 : CallingConv<[
111 // If FastCC, use RetCC_X86_32_Fast.
Chris Lattner370bdda2007-02-28 05:30:29 +0000112 CCIfCC<"CallingConv::Fast", CCDelegateTo<RetCC_X86_32_Fast>>,
Chris Lattnerd50110d2007-02-27 05:51:05 +0000113 // Otherwise, use RetCC_X86_32_C.
114 CCDelegateTo<RetCC_X86_32_C>
115]>;
116
117// This is the root return-value convention for the X86-64 backend.
118def RetCC_X86_64 : CallingConv<[
Anton Korobeynikov8f88cb02008-03-22 20:37:30 +0000119 // Mingw64 and native Win64 use Win64 CC
Anton Korobeynikov1a979d92008-03-22 20:57:27 +0000120 CCIfSubtarget<"isTargetWin64()", CCDelegateTo<RetCC_X86_Win64_C>>,
Anton Korobeynikov8f88cb02008-03-22 20:37:30 +0000121
122 // Otherwise, drop to normal X86-64 CC
Chris Lattnerd50110d2007-02-27 05:51:05 +0000123 CCDelegateTo<RetCC_X86_64_C>
124]>;
125
Chris Lattnerd637a8b2007-02-27 06:59:52 +0000126// This is the return-value convention used for the entire X86 backend.
127def RetCC_X86 : CallingConv<[
Chris Lattner370bdda2007-02-28 05:30:29 +0000128 CCIfSubtarget<"is64Bit()", CCDelegateTo<RetCC_X86_64>>,
Chris Lattnerd637a8b2007-02-27 06:59:52 +0000129 CCDelegateTo<RetCC_X86_32>
130]>;
Chris Lattnerd50110d2007-02-27 05:51:05 +0000131
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000132//===----------------------------------------------------------------------===//
Chris Lattner370bdda2007-02-28 05:30:29 +0000133// X86-64 Argument Calling Conventions
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000134//===----------------------------------------------------------------------===//
135
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000136def CC_X86_64_C : CallingConv<[
Evan Chengbdfd5ef2008-01-15 03:15:41 +0000137 // Handles byval parameters.
Evan Cheng6bfa8a12008-01-15 03:34:58 +0000138 CCIfByVal<CCPassByVal<8, 8>>,
Evan Chengbdfd5ef2008-01-15 03:15:41 +0000139
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000140 // Promote i8/i16 arguments to i32.
Chris Lattner370bdda2007-02-28 05:30:29 +0000141 CCIfType<[i8, i16], CCPromoteToType<i32>>,
Duncan Sands4bdad512008-01-19 16:42:10 +0000142
143 // The 'nest' parameter, if any, is passed in R10.
144 CCIfNest<CCAssignToReg<[R10]>>,
145
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000146 // The first 6 integer arguments are passed in integer registers.
Chris Lattner370bdda2007-02-28 05:30:29 +0000147 CCIfType<[i32], CCAssignToReg<[EDI, ESI, EDX, ECX, R8D, R9D]>>,
148 CCIfType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8 , R9 ]>>,
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000149
Eli Friedmanadebeea2011-07-01 21:33:28 +0000150 // The first 8 MMX vector arguments are passed in XMM registers on Darwin.
Dale Johannesen0488fb62010-09-30 23:57:10 +0000151 CCIfType<[x86mmx],
Evan Chengee472b12008-04-25 07:56:45 +0000152 CCIfSubtarget<"isTargetDarwin()",
Craig Topper1accb7e2012-01-10 06:54:16 +0000153 CCIfSubtarget<"hasSSE2()",
Anton Korobeynikov80cb8aa2009-08-03 08:13:24 +0000154 CCPromoteToType<v2i64>>>>,
Bill Wendlingdb5c9932007-03-31 01:03:53 +0000155
Anton Korobeynikov80cb8aa2009-08-03 08:13:24 +0000156 // The first 8 FP/Vector arguments are passed in XMM registers.
157 CCIfType<[f32, f64, v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
Craig Topper1accb7e2012-01-10 06:54:16 +0000158 CCIfSubtarget<"hasSSE1()",
Anton Korobeynikov80cb8aa2009-08-03 08:13:24 +0000159 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7]>>>,
Bruno Cardoso Lopesac098352010-08-05 23:35:51 +0000160
Eli Friedman522fb8c2011-12-01 04:49:21 +0000161 // The first 8 256-bit vector arguments are passed in YMM registers, unless
162 // this is a vararg function.
163 // FIXME: This isn't precisely correct; the x86-64 ABI document says that
164 // fixed arguments to vararg functions are supposed to be passed in
165 // registers. Actually modeling that would be a lot of work, though.
166 CCIfNotVarArg<CCIfType<[v32i8, v16i16, v8i32, v4i64, v8f32, v4f64],
167 CCIfSubtarget<"hasAVX()",
168 CCAssignToReg<[YMM0, YMM1, YMM2, YMM3,
169 YMM4, YMM5, YMM6, YMM7]>>>>,
Bruno Cardoso Lopesac098352010-08-05 23:35:51 +0000170
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000171 // Integer/FP values get stored in stack slots that are 8 bytes in size and
172 // 8-byte aligned if there are no more registers to hold them.
Chris Lattner370bdda2007-02-28 05:30:29 +0000173 CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>,
Bruno Cardoso Lopesac098352010-08-05 23:35:51 +0000174
Dale Johannesene3ef7442007-11-10 22:07:15 +0000175 // Long doubles get stack slots whose size and alignment depends on the
176 // subtarget.
Duncan Sands87b665d2007-11-14 08:29:13 +0000177 CCIfType<[f80], CCAssignToStack<0, 0>>,
Dale Johannesene3ef7442007-11-10 22:07:15 +0000178
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000179 // Vectors get 16-byte stack slots that are 16-byte aligned.
Dale Johannesene3ef7442007-11-10 22:07:15 +0000180 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToStack<16, 16>>,
Bill Wendlinge2501b32007-03-30 00:35:22 +0000181
Bruno Cardoso Lopesac098352010-08-05 23:35:51 +0000182 // 256-bit vectors get 32-byte stack slots that are 32-byte aligned.
183 CCIfType<[v32i8, v16i16, v8i32, v4i64, v8f32, v4f64],
Eli Friedmanadebeea2011-07-01 21:33:28 +0000184 CCAssignToStack<32, 32>>
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000185]>;
186
Anton Korobeynikov8f88cb02008-03-22 20:37:30 +0000187// Calling convention used on Win64
188def CC_X86_Win64_C : CallingConv<[
Anton Korobeynikov82818eb2008-03-23 20:32:06 +0000189 // FIXME: Handle byval stuff.
Anton Korobeynikov67073f12008-04-02 05:23:57 +0000190 // FIXME: Handle varargs.
Anton Korobeynikov8f88cb02008-03-22 20:37:30 +0000191
192 // Promote i8/i16 arguments to i32.
193 CCIfType<[i8, i16], CCPromoteToType<i32>>,
194
Anton Korobeynikov67073f12008-04-02 05:23:57 +0000195 // The 'nest' parameter, if any, is passed in R10.
196 CCIfNest<CCAssignToReg<[R10]>>,
197
Anton Korobeynikov4ab15532009-08-03 08:13:56 +0000198 // 128 bit vectors are passed by pointer
199 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCPassIndirect<i64>>,
200
Elena Demikhovsky17669712012-02-01 10:46:14 +0000201
202 // 256 bit vectors are passed by pointer
203 CCIfType<[v32i8, v16i16, v8i32, v4i64, v8f32, v4f64], CCPassIndirect<i64>>,
204
Anton Korobeynikov4ab15532009-08-03 08:13:56 +0000205 // The first 4 MMX vector arguments are passed in GPRs.
Eli Friedmanadebeea2011-07-01 21:33:28 +0000206 CCIfType<[x86mmx], CCBitConvertToType<i64>>,
Anton Korobeynikov4ab15532009-08-03 08:13:56 +0000207
Anton Korobeynikov8f88cb02008-03-22 20:37:30 +0000208 // The first 4 integer arguments are passed in integer registers.
Anton Korobeynikov67073f12008-04-02 05:23:57 +0000209 CCIfType<[i32], CCAssignToRegWithShadow<[ECX , EDX , R8D , R9D ],
210 [XMM0, XMM1, XMM2, XMM3]>>,
Tilmann Schellerf1cc70c2011-03-02 19:29:22 +0000211
212 // Do not pass the sret argument in RCX, the Win64 thiscall calling
213 // convention requires "this" to be passed in RCX.
Tilmann Scheller49d79992011-03-03 07:49:07 +0000214 CCIfCC<"CallingConv::X86_ThisCall",
Tilmann Schellerf1cc70c2011-03-02 19:29:22 +0000215 CCIfSRet<CCIfType<[i64], CCAssignToRegWithShadow<[RDX , R8 , R9 ],
216 [XMM1, XMM2, XMM3]>>>>,
217
Anton Korobeynikov67073f12008-04-02 05:23:57 +0000218 CCIfType<[i64], CCAssignToRegWithShadow<[RCX , RDX , R8 , R9 ],
219 [XMM0, XMM1, XMM2, XMM3]>>,
Anton Korobeynikov8f88cb02008-03-22 20:37:30 +0000220
221 // The first 4 FP/Vector arguments are passed in XMM registers.
222 CCIfType<[f32, f64, v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
Anton Korobeynikov67073f12008-04-02 05:23:57 +0000223 CCAssignToRegWithShadow<[XMM0, XMM1, XMM2, XMM3],
224 [RCX , RDX , R8 , R9 ]>>,
Anton Korobeynikov8f88cb02008-03-22 20:37:30 +0000225
Anton Korobeynikov8f88cb02008-03-22 20:37:30 +0000226 // Integer/FP values get stored in stack slots that are 8 bytes in size and
Anton Korobeynikovcf6b7392009-08-03 08:12:53 +0000227 // 8-byte aligned if there are no more registers to hold them.
228 CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>,
Anton Korobeynikov8f88cb02008-03-22 20:37:30 +0000229
Anton Korobeynikov72551932008-04-27 22:54:09 +0000230 // Long doubles get stack slots whose size and alignment depends on the
231 // subtarget.
Eli Friedmanadebeea2011-07-01 21:33:28 +0000232 CCIfType<[f80], CCAssignToStack<0, 0>>
Anton Korobeynikov8f88cb02008-03-22 20:37:30 +0000233]>;
234
Chris Lattner29689432010-03-11 00:22:57 +0000235def CC_X86_64_GHC : CallingConv<[
236 // Promote i8/i16/i32 arguments to i64.
237 CCIfType<[i8, i16, i32], CCPromoteToType<i64>>,
238
239 // Pass in STG registers: Base, Sp, Hp, R1, R2, R3, R4, R5, R6, SpLim
240 CCIfType<[i64],
241 CCAssignToReg<[R13, RBP, R12, RBX, R14, RSI, RDI, R8, R9, R15]>>,
242
243 // Pass in STG registers: F1, F2, F3, F4, D1, D2
244 CCIfType<[f32, f64, v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
Craig Topper1accb7e2012-01-10 06:54:16 +0000245 CCIfSubtarget<"hasSSE1()",
Chris Lattner29689432010-03-11 00:22:57 +0000246 CCAssignToReg<[XMM1, XMM2, XMM3, XMM4, XMM5, XMM6]>>>
247]>;
248
Chris Lattner423c5f42007-02-28 05:31:48 +0000249//===----------------------------------------------------------------------===//
250// X86 C Calling Convention
251//===----------------------------------------------------------------------===//
252
Chris Lattner011bcc82007-02-28 06:20:01 +0000253/// CC_X86_32_Common - In all X86-32 calling conventions, extra integers and FP
254/// values are spilled on the stack, and the first 4 vector values go in XMM
255/// regs.
256def CC_X86_32_Common : CallingConv<[
Evan Chengbdfd5ef2008-01-15 03:15:41 +0000257 // Handles byval parameters.
Evan Cheng6bfa8a12008-01-15 03:34:58 +0000258 CCIfByVal<CCPassByVal<4, 4>>,
Evan Chengbdfd5ef2008-01-15 03:15:41 +0000259
Dale Johannesene672af12008-02-05 20:46:33 +0000260 // The first 3 float or double arguments, if marked 'inreg' and if the call
261 // is not a vararg call and if SSE2 is available, are passed in SSE registers.
Evan Chengee472b12008-04-25 07:56:45 +0000262 CCIfNotVarArg<CCIfInReg<CCIfType<[f32,f64],
Craig Topper1accb7e2012-01-10 06:54:16 +0000263 CCIfSubtarget<"hasSSE2()",
Dale Johannesene672af12008-02-05 20:46:33 +0000264 CCAssignToReg<[XMM0,XMM1,XMM2]>>>>>,
265
Eli Friedmanadebeea2011-07-01 21:33:28 +0000266 // The first 3 __m64 vector arguments are passed in mmx registers if the
267 // call is not a vararg call.
Dale Johannesen0488fb62010-09-30 23:57:10 +0000268 CCIfNotVarArg<CCIfType<[x86mmx],
Evan Chengee472b12008-04-25 07:56:45 +0000269 CCAssignToReg<[MM0, MM1, MM2]>>>,
270
Chris Lattner011bcc82007-02-28 06:20:01 +0000271 // Integer/Float values get stored in stack slots that are 4 bytes in
272 // size and 4-byte aligned.
273 CCIfType<[i32, f32], CCAssignToStack<4, 4>>,
274
275 // Doubles get 8-byte slots that are 4-byte aligned.
276 CCIfType<[f64], CCAssignToStack<8, 4>>,
Dale Johannesen6a308112007-08-06 21:31:06 +0000277
Duncan Sands30d157512008-01-07 16:36:38 +0000278 // Long doubles get slots whose size depends on the subtarget.
279 CCIfType<[f80], CCAssignToStack<0, 4>>,
Dale Johannesen6a308112007-08-06 21:31:06 +0000280
Dale Johannesen3edd6dc2008-02-22 17:47:28 +0000281 // The first 4 SSE vector arguments are passed in XMM registers.
Evan Cheng2cbdd272008-01-22 23:26:53 +0000282 CCIfNotVarArg<CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
283 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3]>>>,
Chris Lattner011bcc82007-02-28 06:20:01 +0000284
Bruno Cardoso Lopesac098352010-08-05 23:35:51 +0000285 // The first 4 AVX 256-bit vector arguments are passed in YMM registers.
286 CCIfNotVarArg<CCIfType<[v32i8, v16i16, v8i32, v4i64, v8f32, v4f64],
287 CCIfSubtarget<"hasAVX()",
288 CCAssignToReg<[YMM0, YMM1, YMM2, YMM3]>>>>,
289
Dale Johannesen3edd6dc2008-02-22 17:47:28 +0000290 // Other SSE vectors get 16-byte stack slots that are 16-byte aligned.
Bill Wendlinge2501b32007-03-30 00:35:22 +0000291 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToStack<16, 16>>,
292
Bruno Cardoso Lopesac098352010-08-05 23:35:51 +0000293 // 256-bit AVX vectors get 32-byte stack slots that are 32-byte aligned.
294 CCIfType<[v32i8, v16i16, v8i32, v4i64, v8f32, v4f64],
295 CCAssignToStack<32, 32>>,
296
Dale Johannesen3edd6dc2008-02-22 17:47:28 +0000297 // __m64 vectors get 8-byte stack slots that are 4-byte aligned. They are
Bill Wendlinge2501b32007-03-30 00:35:22 +0000298 // passed in the parameter area.
Eli Friedmanadebeea2011-07-01 21:33:28 +0000299 CCIfType<[x86mmx], CCAssignToStack<8, 4>>]>;
Chris Lattner011bcc82007-02-28 06:20:01 +0000300
Chris Lattner423c5f42007-02-28 05:31:48 +0000301def CC_X86_32_C : CallingConv<[
302 // Promote i8/i16 arguments to i32.
303 CCIfType<[i8, i16], CCPromoteToType<i32>>,
Duncan Sandsb116fac2007-07-27 20:02:49 +0000304
305 // The 'nest' parameter, if any, is passed in ECX.
306 CCIfNest<CCAssignToReg<[ECX]>>,
307
Chris Lattner52387be2007-06-19 00:13:10 +0000308 // The first 3 integer arguments, if marked 'inreg' and if the call is not
309 // a vararg call, are passed in integer registers.
310 CCIfNotVarArg<CCIfInReg<CCIfType<[i32], CCAssignToReg<[EAX, EDX, ECX]>>>>,
Duncan Sandsb116fac2007-07-27 20:02:49 +0000311
Chris Lattner011bcc82007-02-28 06:20:01 +0000312 // Otherwise, same as everything else.
313 CCDelegateTo<CC_X86_32_Common>
Chris Lattner423c5f42007-02-28 05:31:48 +0000314]>;
315
Chris Lattner011bcc82007-02-28 06:20:01 +0000316def CC_X86_32_FastCall : CallingConv<[
317 // Promote i8/i16 arguments to i32.
318 CCIfType<[i8, i16], CCPromoteToType<i32>>,
Duncan Sandsb116fac2007-07-27 20:02:49 +0000319
320 // The 'nest' parameter, if any, is passed in EAX.
321 CCIfNest<CCAssignToReg<[EAX]>>,
322
Chris Lattner011bcc82007-02-28 06:20:01 +0000323 // The first 2 integer arguments are passed in ECX/EDX
Chris Lattner70500802007-02-28 18:35:11 +0000324 CCIfType<[i32], CCAssignToReg<[ECX, EDX]>>,
Duncan Sandsb116fac2007-07-27 20:02:49 +0000325
Chris Lattner011bcc82007-02-28 06:20:01 +0000326 // Otherwise, same as everything else.
327 CCDelegateTo<CC_X86_32_Common>
328]>;
Evan Cheng4a037752008-09-04 22:59:58 +0000329
Anton Korobeynikovded05e32010-05-16 09:08:45 +0000330def CC_X86_32_ThisCall : CallingConv<[
331 // Promote i8/i16 arguments to i32.
332 CCIfType<[i8, i16], CCPromoteToType<i32>>,
333
Aaron Ballman57708ab2012-02-22 03:04:40 +0000334 // Pass sret arguments indirectly through EAX
335 CCIfSRet<CCAssignToReg<[EAX]>>,
Anton Korobeynikovded05e32010-05-16 09:08:45 +0000336
337 // The first integer argument is passed in ECX
338 CCIfType<[i32], CCAssignToReg<[ECX]>>,
339
340 // Otherwise, same as everything else.
341 CCDelegateTo<CC_X86_32_Common>
342]>;
343
Evan Cheng4a037752008-09-04 22:59:58 +0000344def CC_X86_32_FastCC : CallingConv<[
Dan Gohmane4300e22008-12-03 01:28:04 +0000345 // Handles byval parameters. Note that we can't rely on the delegation
346 // to CC_X86_32_Common for this because that happens after code that
Dan Gohmanc5a1a222008-12-03 01:39:44 +0000347 // puts arguments in registers.
Dan Gohmane4300e22008-12-03 01:28:04 +0000348 CCIfByVal<CCPassByVal<4, 4>>,
349
Evan Cheng4a037752008-09-04 22:59:58 +0000350 // Promote i8/i16 arguments to i32.
351 CCIfType<[i8, i16], CCPromoteToType<i32>>,
352
353 // The 'nest' parameter, if any, is passed in EAX.
354 CCIfNest<CCAssignToReg<[EAX]>>,
355
356 // The first 2 integer arguments are passed in ECX/EDX
357 CCIfType<[i32], CCAssignToReg<[ECX, EDX]>>,
358
Evan Chenge2471a92008-09-05 17:24:07 +0000359 // The first 3 float or double arguments, if the call is not a vararg
360 // call and if SSE2 is available, are passed in SSE registers.
361 CCIfNotVarArg<CCIfType<[f32,f64],
Craig Topper1accb7e2012-01-10 06:54:16 +0000362 CCIfSubtarget<"hasSSE2()",
Evan Chenge2471a92008-09-05 17:24:07 +0000363 CCAssignToReg<[XMM0,XMM1,XMM2]>>>>,
364
Evan Cheng4a037752008-09-04 22:59:58 +0000365 // Doubles get 8-byte slots that are 8-byte aligned.
366 CCIfType<[f64], CCAssignToStack<8, 8>>,
367
368 // Otherwise, same as everything else.
369 CCDelegateTo<CC_X86_32_Common>
370]>;
Chris Lattner29689432010-03-11 00:22:57 +0000371
372def CC_X86_32_GHC : CallingConv<[
373 // Promote i8/i16 arguments to i32.
374 CCIfType<[i8, i16], CCPromoteToType<i32>>,
375
376 // Pass in STG registers: Base, Sp, Hp, R1
377 CCIfType<[i32], CCAssignToReg<[EBX, EBP, EDI, ESI]>>
378]>;
Duncan Sands45907662010-10-31 13:21:44 +0000379
380//===----------------------------------------------------------------------===//
381// X86 Root Argument Calling Conventions
382//===----------------------------------------------------------------------===//
383
384// This is the root argument convention for the X86-32 backend.
385def CC_X86_32 : CallingConv<[
386 CCIfCC<"CallingConv::X86_FastCall", CCDelegateTo<CC_X86_32_FastCall>>,
387 CCIfCC<"CallingConv::X86_ThisCall", CCDelegateTo<CC_X86_32_ThisCall>>,
388 CCIfCC<"CallingConv::Fast", CCDelegateTo<CC_X86_32_FastCC>>,
389 CCIfCC<"CallingConv::GHC", CCDelegateTo<CC_X86_32_GHC>>,
390
391 // Otherwise, drop to normal X86-32 CC
392 CCDelegateTo<CC_X86_32_C>
393]>;
394
395// This is the root argument convention for the X86-64 backend.
396def CC_X86_64 : CallingConv<[
397 CCIfCC<"CallingConv::GHC", CCDelegateTo<CC_X86_64_GHC>>,
398
399 // Mingw64 and native Win64 use Win64 CC
400 CCIfSubtarget<"isTargetWin64()", CCDelegateTo<CC_X86_Win64_C>>,
401
402 // Otherwise, drop to normal X86-64 CC
403 CCDelegateTo<CC_X86_64_C>
404]>;
405
406// This is the argument convention used for the entire X86 backend.
407def CC_X86 : CallingConv<[
408 CCIfSubtarget<"is64Bit()", CCDelegateTo<CC_X86_64>>,
409 CCDelegateTo<CC_X86_32>
410]>;
Jakob Stoklund Olesen0bd2ae92012-01-17 22:47:01 +0000411
412//===----------------------------------------------------------------------===//
413// Callee-saved Registers.
414//===----------------------------------------------------------------------===//
415
Jakob Stoklund Olesen1910cb12012-05-08 15:07:29 +0000416def CSR_NoRegs : CalleeSavedRegs<(add)>;
Jakob Stoklund Olesen0bd2ae92012-01-17 22:47:01 +0000417
418def CSR_32 : CalleeSavedRegs<(add ESI, EDI, EBX, EBP)>;
419def CSR_64 : CalleeSavedRegs<(add RBX, R12, R13, R14, R15, RBP)>;
420
421def CSR_32EHRet : CalleeSavedRegs<(add EAX, EDX, CSR_32)>;
422def CSR_64EHRet : CalleeSavedRegs<(add RAX, RDX, CSR_64)>;
423
424def CSR_Win64 : CalleeSavedRegs<(add RBX, RBP, RDI, RSI, R12, R13, R14, R15,
425 (sequence "XMM%u", 6, 15))>;