1 //===- X86CallingConv.td - Calling Conventions for X86 32/64 ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
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.
26 CCIfType<[i8] , CCAssignToReg<[AL]>>,
27 CCIfType<[i16], CCAssignToReg<[AX]>>,
28 CCIfType<[i32], CCAssignToReg<[EAX, EDX]>>,
29 CCIfType<[i64], CCAssignToReg<[RAX, RDX]>>,
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]>>,
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]>>
41 // X86-32 C return-value convention.
42 def RetCC_X86_32_C : CallingConv<[
43 // The X86-32 calling convention returns FP values in ST0, otherwise it is the
44 // same as the common X86 calling conv.
45 CCIfType<[f32], CCAssignToReg<[ST0]>>,
46 CCIfType<[f64], CCAssignToReg<[ST0]>>,
47 CCDelegateTo<RetCC_X86Common>
50 // X86-32 FastCC return-value convention.
51 def RetCC_X86_32_Fast : CallingConv<[
52 // The X86-32 fastcc returns FP values in XMM0 if the target has SSE2,
53 // otherwise it is the the C calling conventions.
54 CCIfType<[f32], CCIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0]>>>,
55 CCIfType<[f64], CCIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0]>>>,
56 CCDelegateTo<RetCC_X86Common>
59 // X86-64 C return-value convention.
60 def RetCC_X86_64_C : CallingConv<[
61 // The X86-64 calling convention always returns FP values in XMM0.
62 CCIfType<[f32], CCAssignToReg<[XMM0]>>,
63 CCIfType<[f64], CCAssignToReg<[XMM0]>>,
64 CCDelegateTo<RetCC_X86Common>
69 // This is the root return-value convention for the X86-32 backend.
70 def RetCC_X86_32 : CallingConv<[
71 // If FastCC, use RetCC_X86_32_Fast.
72 CCIfCC<"CallingConv::Fast", CCDelegateTo<RetCC_X86_32_Fast>>,
73 // Otherwise, use RetCC_X86_32_C.
74 CCDelegateTo<RetCC_X86_32_C>
77 // This is the root return-value convention for the X86-64 backend.
78 def RetCC_X86_64 : CallingConv<[
79 // Always just the same as C calling conv for X86-64.
80 CCDelegateTo<RetCC_X86_64_C>
83 // This is the return-value convention used for the entire X86 backend.
84 def RetCC_X86 : CallingConv<[
85 CCIfSubtarget<"is64Bit()", CCDelegateTo<RetCC_X86_64>>,
86 CCDelegateTo<RetCC_X86_32>
89 //===----------------------------------------------------------------------===//
90 // X86-64 Argument Calling Conventions
91 //===----------------------------------------------------------------------===//
93 def CC_X86_64_C : CallingConv<[
94 // Promote i8/i16 arguments to i32.
95 CCIfType<[i8, i16], CCPromoteToType<i32>>,
97 CCIfStruct<CCStructAssign<[RDI, RSI, RDX, RCX, R8, R9 ]>>,
99 // The first 6 integer arguments are passed in integer registers.
100 CCIfType<[i32], CCAssignToReg<[EDI, ESI, EDX, ECX, R8D, R9D]>>,
101 CCIfType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8 , R9 ]>>,
103 // The first 8 FP/Vector arguments are passed in XMM registers.
104 CCIfType<[f32, f64, v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
105 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7]>>,
107 // The first 8 MMX vector arguments are passed in GPRs.
108 CCIfType<[v8i8, v4i16, v2i32, v1i64],
109 CCAssignToReg<[RDI, RSI, RDX, RCX, R8 , R9 ]>>,
111 // Integer/FP values get stored in stack slots that are 8 bytes in size and
112 // 8-byte aligned if there are no more registers to hold them.
113 CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>,
115 // Vectors get 16-byte stack slots that are 16-byte aligned.
116 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToStack<16, 16>>,
118 // __m64 vectors get 8-byte stack slots that are 8-byte aligned.
119 CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToStack<8, 8>>
123 //===----------------------------------------------------------------------===//
124 // X86 C Calling Convention
125 //===----------------------------------------------------------------------===//
127 /// CC_X86_32_Common - In all X86-32 calling conventions, extra integers and FP
128 /// values are spilled on the stack, and the first 4 vector values go in XMM
130 def CC_X86_32_Common : CallingConv<[
131 // Integer/Float values get stored in stack slots that are 4 bytes in
132 // size and 4-byte aligned.
133 CCIfType<[i32, f32], CCAssignToStack<4, 4>>,
135 // Doubles get 8-byte slots that are 4-byte aligned.
136 CCIfType<[f64], CCAssignToStack<8, 4>>,
138 // The first 4 vector arguments are passed in XMM registers.
139 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
140 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3]>>,
142 // Other vectors get 16-byte stack slots that are 16-byte aligned.
143 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToStack<16, 16>>,
145 // __m64 vectors get 8-byte stack slots that are 8-byte aligned. They are
146 // passed in the parameter area.
147 CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToStack<8, 8>>
150 def CC_X86_32_C : CallingConv<[
151 // Promote i8/i16 arguments to i32.
152 CCIfType<[i8, i16], CCPromoteToType<i32>>,
154 // The first 3 integer arguments, if marked 'inreg' and if the call is not
155 // a vararg call, are passed in integer registers.
156 CCIfNotVarArg<CCIfInReg<CCIfType<[i32], CCAssignToReg<[EAX, EDX, ECX]>>>>,
158 // Otherwise, same as everything else.
159 CCDelegateTo<CC_X86_32_Common>
163 def CC_X86_32_FastCall : CallingConv<[
164 // Promote i8/i16 arguments to i32.
165 CCIfType<[i8, i16], CCPromoteToType<i32>>,
167 // The first 2 integer arguments are passed in ECX/EDX
168 CCIfType<[i32], CCAssignToReg<[ECX, EDX]>>,
170 // Otherwise, same as everything else.
171 CCDelegateTo<CC_X86_32_Common>