blob: 39811bd7409de03007be2bbc2a599f723bb72ebf [file] [log] [blame]
Chris Lattner31c8a6d2007-02-26 18:17:14 +00001//===- X86CallingConv.td - Calling Conventions for X86 32/64 ----*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerbffc1b32007-02-26 18:56:07 +00005// This file was developed by Chris Lattner and is distributed under
Chris Lattner31c8a6d2007-02-26 18:17:14 +00006// 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
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.
38 CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToReg<[MM0]>>
Chris Lattner31c8a6d2007-02-26 18:17:14 +000039]>;
40
Chris Lattnerd50110d2007-02-27 05:51:05 +000041// X86-32 C return-value convention.
Chris Lattner31c8a6d2007-02-26 18:17:14 +000042def 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.
Chris Lattner370bdda2007-02-28 05:30:29 +000045 CCIfType<[f32], CCAssignToReg<[ST0]>>,
46 CCIfType<[f64], CCAssignToReg<[ST0]>>,
Chris Lattner31c8a6d2007-02-26 18:17:14 +000047 CCDelegateTo<RetCC_X86Common>
48]>;
49
Chris Lattnerd50110d2007-02-27 05:51:05 +000050// X86-32 FastCC return-value convention.
Chris Lattner31c8a6d2007-02-26 18:17:14 +000051def 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.
Chris Lattner370bdda2007-02-28 05:30:29 +000054 CCIfType<[f32], CCIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0]>>>,
55 CCIfType<[f64], CCIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0]>>>,
Chris Lattner31c8a6d2007-02-26 18:17:14 +000056 CCDelegateTo<RetCC_X86Common>
57]>;
58
Chris Lattnerd50110d2007-02-27 05:51:05 +000059// X86-64 C return-value convention.
Chris Lattner31c8a6d2007-02-26 18:17:14 +000060def RetCC_X86_64_C : CallingConv<[
61 // The X86-64 calling convention always returns FP values in XMM0.
Chris Lattner370bdda2007-02-28 05:30:29 +000062 CCIfType<[f32], CCAssignToReg<[XMM0]>>,
63 CCIfType<[f64], CCAssignToReg<[XMM0]>>,
Chris Lattner31c8a6d2007-02-26 18:17:14 +000064 CCDelegateTo<RetCC_X86Common>
65]>;
66
67
Chris Lattnerd50110d2007-02-27 05:51:05 +000068
69// This is the root return-value convention for the X86-32 backend.
70def RetCC_X86_32 : CallingConv<[
71 // If FastCC, use RetCC_X86_32_Fast.
Chris Lattner370bdda2007-02-28 05:30:29 +000072 CCIfCC<"CallingConv::Fast", CCDelegateTo<RetCC_X86_32_Fast>>,
Chris Lattnerd50110d2007-02-27 05:51:05 +000073 // Otherwise, use RetCC_X86_32_C.
74 CCDelegateTo<RetCC_X86_32_C>
75]>;
76
77// This is the root return-value convention for the X86-64 backend.
78def RetCC_X86_64 : CallingConv<[
79 // Always just the same as C calling conv for X86-64.
80 CCDelegateTo<RetCC_X86_64_C>
81]>;
82
Chris Lattnerd637a8b2007-02-27 06:59:52 +000083// This is the return-value convention used for the entire X86 backend.
84def RetCC_X86 : CallingConv<[
Chris Lattner370bdda2007-02-28 05:30:29 +000085 CCIfSubtarget<"is64Bit()", CCDelegateTo<RetCC_X86_64>>,
Chris Lattnerd637a8b2007-02-27 06:59:52 +000086 CCDelegateTo<RetCC_X86_32>
87]>;
Chris Lattnerd50110d2007-02-27 05:51:05 +000088
Chris Lattner31c8a6d2007-02-26 18:17:14 +000089//===----------------------------------------------------------------------===//
Chris Lattner370bdda2007-02-28 05:30:29 +000090// X86-64 Argument Calling Conventions
Chris Lattner31c8a6d2007-02-26 18:17:14 +000091//===----------------------------------------------------------------------===//
92
Chris Lattner31c8a6d2007-02-26 18:17:14 +000093def CC_X86_64_C : CallingConv<[
94 // Promote i8/i16 arguments to i32.
Chris Lattner370bdda2007-02-28 05:30:29 +000095 CCIfType<[i8, i16], CCPromoteToType<i32>>,
Chris Lattner31c8a6d2007-02-26 18:17:14 +000096
Rafael Espindola1aa7efb2007-07-06 10:57:03 +000097 CCIfStruct<CCStructAssign<[RDI, RSI, RDX, RCX, R8, R9 ]>>,
98
Chris Lattner31c8a6d2007-02-26 18:17:14 +000099 // The first 6 integer arguments are passed in integer registers.
Chris Lattner370bdda2007-02-28 05:30:29 +0000100 CCIfType<[i32], CCAssignToReg<[EDI, ESI, EDX, ECX, R8D, R9D]>>,
101 CCIfType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8 , R9 ]>>,
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000102
103 // The first 8 FP/Vector arguments are passed in XMM registers.
Chris Lattner370bdda2007-02-28 05:30:29 +0000104 CCIfType<[f32, f64, v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000105 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7]>>,
106
Bill Wendling577c7d92007-03-31 09:36:12 +0000107 // The first 8 MMX vector arguments are passed in GPRs.
Bill Wendlingdb5c9932007-03-31 01:03:53 +0000108 CCIfType<[v8i8, v4i16, v2i32, v1i64],
109 CCAssignToReg<[RDI, RSI, RDX, RCX, R8 , R9 ]>>,
110
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000111 // 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.
Chris Lattner370bdda2007-02-28 05:30:29 +0000113 CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>,
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000114
115 // Vectors get 16-byte stack slots that are 16-byte aligned.
Bill Wendlinge2501b32007-03-30 00:35:22 +0000116 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToStack<16, 16>>,
117
118 // __m64 vectors get 8-byte stack slots that are 8-byte aligned.
119 CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToStack<8, 8>>
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000120]>;
121
122
Chris Lattner423c5f42007-02-28 05:31:48 +0000123//===----------------------------------------------------------------------===//
124// X86 C Calling Convention
125//===----------------------------------------------------------------------===//
126
Chris Lattner011bcc82007-02-28 06:20:01 +0000127/// 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
129/// regs.
130def 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>>,
134
135 // Doubles get 8-byte slots that are 4-byte aligned.
136 CCIfType<[f64], CCAssignToStack<8, 4>>,
137
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]>>,
141
142 // Other vectors get 16-byte stack slots that are 16-byte aligned.
Bill Wendlinge2501b32007-03-30 00:35:22 +0000143 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToStack<16, 16>>,
144
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>>
Chris Lattner011bcc82007-02-28 06:20:01 +0000148]>;
149
Chris Lattner423c5f42007-02-28 05:31:48 +0000150def CC_X86_32_C : CallingConv<[
151 // Promote i8/i16 arguments to i32.
152 CCIfType<[i8, i16], CCPromoteToType<i32>>,
153
Chris Lattner52387be2007-06-19 00:13:10 +0000154 // 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]>>>>,
Chris Lattner423c5f42007-02-28 05:31:48 +0000157
Chris Lattner011bcc82007-02-28 06:20:01 +0000158 // Otherwise, same as everything else.
159 CCDelegateTo<CC_X86_32_Common>
Chris Lattner423c5f42007-02-28 05:31:48 +0000160]>;
161
162
Chris Lattner011bcc82007-02-28 06:20:01 +0000163def CC_X86_32_FastCall : CallingConv<[
164 // Promote i8/i16 arguments to i32.
165 CCIfType<[i8, i16], CCPromoteToType<i32>>,
166
167 // The first 2 integer arguments are passed in ECX/EDX
Chris Lattner70500802007-02-28 18:35:11 +0000168 CCIfType<[i32], CCAssignToReg<[ECX, EDX]>>,
Chris Lattner011bcc82007-02-28 06:20:01 +0000169
170 // Otherwise, same as everything else.
171 CCDelegateTo<CC_X86_32_Common>
172]>;