Add CCAssignToStackABISizeAlign for convenience in
[oota-llvm.git] / lib / Target / X86 / X86CallingConv.td
1 //===- X86CallingConv.td - Calling Conventions X86 32/64 ---*- tablegen -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by Chris Lattner and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This describes the calling conventions for the X86-32 and X86-64
11 // architectures.
12 //
13 //===----------------------------------------------------------------------===//
14
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>;
18
19 //===----------------------------------------------------------------------===//
20 // Return Value Calling Conventions
21 //===----------------------------------------------------------------------===//
22
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.
26   CCIfType<[i8] , CCAssignToReg<[AL]>>,
27   CCIfType<[i16], CCAssignToReg<[AX]>>,
28   CCIfType<[i32], CCAssignToReg<[EAX, EDX]>>,
29   CCIfType<[i64], CCAssignToReg<[RAX, RDX]>>,
30   
31   // 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]>>,
35
36   // MMX vector types are always returned in MM0. If the target doesn't have
37   // MM0, it doesn't support these vector types.
38   CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToReg<[MM0]>>,
39
40   // Long double types are always returned in ST0 (even with SSE).
41   CCIfType<[f80], CCAssignToReg<[ST0]>>
42 ]>;
43
44 // X86-32 C return-value convention.
45 def 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.
48   CCIfType<[f32], CCAssignToReg<[ST0]>>,
49   CCIfType<[f64], CCAssignToReg<[ST0]>>,
50   CCDelegateTo<RetCC_X86Common>
51 ]>;
52
53 // X86-32 FastCC return-value convention.
54 def RetCC_X86_32_Fast : CallingConv<[
55   // The X86-32 fastcc returns FP values in XMM0 if the target has SSE2,
56   // otherwise it is the the C calling conventions.
57   CCIfType<[f32], CCIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0]>>>,
58   CCIfType<[f64], CCIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0]>>>,
59   CCDelegateTo<RetCC_X86Common>
60 ]>;
61
62 // X86-64 C return-value convention.
63 def RetCC_X86_64_C : CallingConv<[
64   // The X86-64 calling convention always returns FP values in XMM0.
65   CCIfType<[f32], CCAssignToReg<[XMM0]>>,
66   CCIfType<[f64], CCAssignToReg<[XMM0]>>,
67   CCDelegateTo<RetCC_X86Common>
68 ]>;
69
70
71
72 // This is the root return-value convention for the X86-32 backend.
73 def RetCC_X86_32 : CallingConv<[
74   // If FastCC, use RetCC_X86_32_Fast.
75   CCIfCC<"CallingConv::Fast", CCDelegateTo<RetCC_X86_32_Fast>>,
76   // Otherwise, use RetCC_X86_32_C.
77   CCDelegateTo<RetCC_X86_32_C>
78 ]>;
79
80 // This is the root return-value convention for the X86-64 backend.
81 def RetCC_X86_64 : CallingConv<[
82   // Always just the same as C calling conv for X86-64.
83   CCDelegateTo<RetCC_X86_64_C>
84 ]>;
85
86 // This is the return-value convention used for the entire X86 backend.
87 def RetCC_X86 : CallingConv<[
88   CCIfSubtarget<"is64Bit()", CCDelegateTo<RetCC_X86_64>>,
89   CCDelegateTo<RetCC_X86_32>
90 ]>;
91
92 //===----------------------------------------------------------------------===//
93 // X86-64 Argument Calling Conventions
94 //===----------------------------------------------------------------------===//
95
96 def CC_X86_64_C : CallingConv<[
97   // Promote i8/i16 arguments to i32.
98   CCIfType<[i8, i16], CCPromoteToType<i32>>,
99   
100   CCIfStruct<CCStructAssign<[RDI, RSI, RDX, RCX, R8, R9 ]>>,
101
102   // The first 6 integer arguments are passed in integer registers.
103   CCIfType<[i32], CCAssignToReg<[EDI, ESI, EDX, ECX, R8D, R9D]>>,
104   CCIfType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8 , R9 ]>>,
105   
106   // The first 8 FP/Vector arguments are passed in XMM registers.
107   CCIfType<[f32, f64, v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
108               CCAssignToReg<[XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7]>>,
109
110   // The first 8 MMX vector arguments are passed in GPRs.
111   CCIfType<[v8i8, v4i16, v2i32, v1i64],
112               CCAssignToReg<[RDI, RSI, RDX, RCX, R8 , R9 ]>>,
113
114   // The 'nest' parameter, if any, is passed in R10.
115   CCIfNest<CCAssignToReg<[R10]>>,
116
117   // Integer/FP values get stored in stack slots that are 8 bytes in size and
118   // 8-byte aligned if there are no more registers to hold them.
119   CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>,
120   
121   // Long doubles get stack slots whose size and alignment depends on the
122   // subtarget.
123   CCIfType<[f80], CCAssignToStackABISizeAlign<0>>,
124
125   // Vectors get 16-byte stack slots that are 16-byte aligned.
126   CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToStack<16, 16>>,
127
128   // __m64 vectors get 8-byte stack slots that are 8-byte aligned.
129   CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToStack<8, 8>>
130 ]>;
131
132 // Tail call convention (fast): One register is reserved for target address,
133 // namely R9
134 def CC_X86_64_TailCall : CallingConv<[
135   // Promote i8/i16 arguments to i32.
136   CCIfType<[i8, i16], CCPromoteToType<i32>>,
137   
138   CCIfStruct<CCStructAssign<[RDI, RSI, RDX, RCX, R8]>>,
139
140   // The first 6 integer arguments are passed in integer registers.
141   CCIfType<[i32], CCAssignToReg<[EDI, ESI, EDX, ECX, R8D]>>,
142   CCIfType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8]>>,
143   
144   // The first 8 FP/Vector arguments are passed in XMM registers.
145   CCIfType<[f32, f64, v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
146               CCAssignToReg<[XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7]>>,
147
148   // The first 8 MMX vector arguments are passed in GPRs.
149   CCIfType<[v8i8, v4i16, v2i32, v1i64],
150               CCAssignToReg<[RDI, RSI, RDX, RCX, R8]>>,
151
152   // The 'nest' parameter, if any, is passed in R10.
153   CCIfNest<CCAssignToReg<[R10]>>,
154
155   // Integer/FP values get stored in stack slots that are 8 bytes in size and
156   // 8-byte aligned if there are no more registers to hold them.
157   CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>,
158   
159   // Vectors get 16-byte stack slots that are 16-byte aligned.
160   CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToStack<16, 16>>,
161
162   // __m64 vectors get 8-byte stack slots that are 8-byte aligned.
163   CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToStack<8, 8>>
164 ]>;
165
166
167 //===----------------------------------------------------------------------===//
168 // X86 C Calling Convention
169 //===----------------------------------------------------------------------===//
170
171 /// CC_X86_32_Common - In all X86-32 calling conventions, extra integers and FP
172 /// values are spilled on the stack, and the first 4 vector values go in XMM
173 /// regs.
174 def CC_X86_32_Common : CallingConv<[
175   // Integer/Float values get stored in stack slots that are 4 bytes in
176   // size and 4-byte aligned.
177   CCIfType<[i32, f32], CCAssignToStack<4, 4>>,
178   
179   // Doubles get 8-byte slots that are 4-byte aligned.
180   CCIfType<[f64], CCAssignToStack<8, 4>>,
181
182   // Long doubles get slots whose size and alignment depends on the
183   // subtarget.
184   CCIfType<[f80], CCAssignToStackABISizeAlign<0>>,
185
186   // The first 4 vector arguments are passed in XMM registers.
187   CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
188               CCAssignToReg<[XMM0, XMM1, XMM2, XMM3]>>,
189
190   // Other vectors get 16-byte stack slots that are 16-byte aligned.
191   CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToStack<16, 16>>,
192
193   // __m64 vectors get 8-byte stack slots that are 8-byte aligned. They are
194   // passed in the parameter area.
195   CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToStack<8, 8>>
196 ]>;
197
198 def CC_X86_32_C : CallingConv<[
199   // Promote i8/i16 arguments to i32.
200   CCIfType<[i8, i16], CCPromoteToType<i32>>,
201
202   // The 'nest' parameter, if any, is passed in ECX.
203   CCIfNest<CCAssignToReg<[ECX]>>,
204
205   // The first 3 integer arguments, if marked 'inreg' and if the call is not
206   // a vararg call, are passed in integer registers.
207   CCIfNotVarArg<CCIfInReg<CCIfType<[i32], CCAssignToReg<[EAX, EDX, ECX]>>>>,
208
209   // Otherwise, same as everything else.
210   CCDelegateTo<CC_X86_32_Common>
211 ]>;
212
213 /// Same as C calling convention except for non-free ECX which is used for storing 
214 /// a potential pointer to the tail called function.
215 def CC_X86_32_TailCall : CallingConv<[
216   // Promote i8/i16 arguments to i32.
217   CCIfType<[i8, i16], CCPromoteToType<i32>>,
218
219   // Nested function trampolines are currently not supported by fastcc.
220   
221   // The first 3 integer arguments, if marked 'inreg' and if the call is not
222   // a vararg call, are passed in integer registers.
223   CCIfNotVarArg<CCIfInReg<CCIfType<[i32], CCAssignToReg<[EAX, EDX]>>>>,
224
225   // Otherwise, same as everything else.
226   CCDelegateTo<CC_X86_32_Common>
227 ]>;
228
229 def CC_X86_32_FastCall : CallingConv<[
230   // Promote i8/i16 arguments to i32.
231   CCIfType<[i8, i16], CCPromoteToType<i32>>,
232
233   // The 'nest' parameter, if any, is passed in EAX.
234   CCIfNest<CCAssignToReg<[EAX]>>,
235
236   // The first 2 integer arguments are passed in ECX/EDX
237   CCIfType<[i32], CCAssignToReg<[ECX, EDX]>>,
238
239   // Otherwise, same as everything else.
240   CCDelegateTo<CC_X86_32_Common>
241 ]>;