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 always returned in XMM0. If the target doesn't have XMM0,
32 // it won't have vector types.
33 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToReg<[XMM0]>>,
35 // MMX vector types are always returned in MM0. If the target doesn't have
36 // MM0, it doesn't support these vector types.
37 CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToReg<[MM0]>>
40 // X86-32 C return-value convention.
41 def RetCC_X86_32_C : CallingConv<[
42 // The X86-32 calling convention returns FP values in ST0, otherwise it is the
43 // same as the common X86 calling conv.
44 CCIfType<[f32], CCAssignToReg<[ST0]>>,
45 CCIfType<[f64], CCAssignToReg<[ST0]>>,
46 CCDelegateTo<RetCC_X86Common>
49 // X86-32 FastCC return-value convention.
50 def RetCC_X86_32_Fast : CallingConv<[
51 // The X86-32 fastcc returns FP values in XMM0 if the target has SSE2,
52 // otherwise it is the the C calling conventions.
53 CCIfType<[f32], CCIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0]>>>,
54 CCIfType<[f64], CCIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0]>>>,
55 CCDelegateTo<RetCC_X86Common>
58 // X86-64 C return-value convention.
59 def RetCC_X86_64_C : CallingConv<[
60 // The X86-64 calling convention always returns FP values in XMM0.
61 CCIfType<[f32], CCAssignToReg<[XMM0]>>,
62 CCIfType<[f64], CCAssignToReg<[XMM0]>>,
63 CCDelegateTo<RetCC_X86Common>
68 // This is the root return-value convention for the X86-32 backend.
69 def RetCC_X86_32 : CallingConv<[
70 // If FastCC, use RetCC_X86_32_Fast.
71 CCIfCC<"CallingConv::Fast", CCDelegateTo<RetCC_X86_32_Fast>>,
72 // Otherwise, use RetCC_X86_32_C.
73 CCDelegateTo<RetCC_X86_32_C>
76 // This is the root return-value convention for the X86-64 backend.
77 def RetCC_X86_64 : CallingConv<[
78 // Always just the same as C calling conv for X86-64.
79 CCDelegateTo<RetCC_X86_64_C>
82 // This is the return-value convention used for the entire X86 backend.
83 def RetCC_X86 : CallingConv<[
84 CCIfSubtarget<"is64Bit()", CCDelegateTo<RetCC_X86_64>>,
85 CCDelegateTo<RetCC_X86_32>
88 //===----------------------------------------------------------------------===//
89 // X86-64 Argument Calling Conventions
90 //===----------------------------------------------------------------------===//
92 def CC_X86_64_C : CallingConv<[
93 // Promote i8/i16 arguments to i32.
94 CCIfType<[i8, i16], CCPromoteToType<i32>>,
96 // The first 6 integer arguments are passed in integer registers.
97 CCIfType<[i32], CCAssignToReg<[EDI, ESI, EDX, ECX, R8D, R9D]>>,
98 CCIfType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8 , R9 ]>>,
100 // The first 8 FP/Vector arguments are passed in XMM registers.
101 CCIfType<[f32, f64, v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
102 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7]>>,
104 // The first 8 MMX vector arguments are passed in MMX registers.
105 CCIfType<[v8i8, v4i16, v2i32, v1i64],
106 CCAssignToReg<[RDI, RSI, RDX, RCX, R8 , R9 ]>>,
108 // Integer/FP values get stored in stack slots that are 8 bytes in size and
109 // 8-byte aligned if there are no more registers to hold them.
110 CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>,
112 // Vectors get 16-byte stack slots that are 16-byte aligned.
113 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToStack<16, 16>>,
115 // __m64 vectors get 8-byte stack slots that are 8-byte aligned.
116 CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToStack<8, 8>>
120 //===----------------------------------------------------------------------===//
121 // X86 C Calling Convention
122 //===----------------------------------------------------------------------===//
124 /// CC_X86_32_Common - In all X86-32 calling conventions, extra integers and FP
125 /// values are spilled on the stack, and the first 4 vector values go in XMM
127 def CC_X86_32_Common : CallingConv<[
128 // Integer/Float values get stored in stack slots that are 4 bytes in
129 // size and 4-byte aligned.
130 CCIfType<[i32, f32], CCAssignToStack<4, 4>>,
132 // Doubles get 8-byte slots that are 4-byte aligned.
133 CCIfType<[f64], CCAssignToStack<8, 4>>,
135 // The first 4 vector arguments are passed in XMM registers.
136 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
137 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3]>>,
139 // Other vectors get 16-byte stack slots that are 16-byte aligned.
140 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToStack<16, 16>>,
142 // __m64 vectors get 8-byte stack slots that are 8-byte aligned. They are
143 // passed in the parameter area.
144 CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToStack<8, 8>>
147 def CC_X86_32_C : CallingConv<[
148 // Promote i8/i16 arguments to i32.
149 CCIfType<[i8, i16], CCPromoteToType<i32>>,
151 // The first 3 integer arguments, if marked 'inreg', are passed in integer
153 CCIfInReg<CCIfType<[i32], CCAssignToReg<[EAX, EDX, ECX]>>>,
155 // Otherwise, same as everything else.
156 CCDelegateTo<CC_X86_32_Common>
160 def CC_X86_32_FastCall : CallingConv<[
161 // Promote i8/i16 arguments to i32.
162 CCIfType<[i8, i16], CCPromoteToType<i32>>,
164 // The first 2 integer arguments are passed in ECX/EDX
165 CCIfType<[i32], CCAssignToReg<[ECX, EDX]>>,
167 // Otherwise, same as everything else.
168 CCDelegateTo<CC_X86_32_Common>