blob: d9a63c4ecd3cdf8d2b4e4481bec4bb37f1096ec8 [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
31 // Vector types are always returned in XMM0. If the target doesn't have XMM0,
32 // it won't have vector types.
Bill Wendlinge2501b32007-03-30 00:35:22 +000033 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToReg<[XMM0]>>,
34
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]>>
Chris Lattner31c8a6d2007-02-26 18:17:14 +000038]>;
39
Chris Lattnerd50110d2007-02-27 05:51:05 +000040// X86-32 C return-value convention.
Chris Lattner31c8a6d2007-02-26 18:17:14 +000041def 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.
Chris Lattner370bdda2007-02-28 05:30:29 +000044 CCIfType<[f32], CCAssignToReg<[ST0]>>,
45 CCIfType<[f64], CCAssignToReg<[ST0]>>,
Chris Lattner31c8a6d2007-02-26 18:17:14 +000046 CCDelegateTo<RetCC_X86Common>
47]>;
48
Chris Lattnerd50110d2007-02-27 05:51:05 +000049// X86-32 FastCC return-value convention.
Chris Lattner31c8a6d2007-02-26 18:17:14 +000050def 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.
Chris Lattner370bdda2007-02-28 05:30:29 +000053 CCIfType<[f32], CCIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0]>>>,
54 CCIfType<[f64], CCIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0]>>>,
Chris Lattner31c8a6d2007-02-26 18:17:14 +000055 CCDelegateTo<RetCC_X86Common>
56]>;
57
Chris Lattnerd50110d2007-02-27 05:51:05 +000058// X86-64 C return-value convention.
Chris Lattner31c8a6d2007-02-26 18:17:14 +000059def RetCC_X86_64_C : CallingConv<[
60 // The X86-64 calling convention always returns FP values in XMM0.
Chris Lattner370bdda2007-02-28 05:30:29 +000061 CCIfType<[f32], CCAssignToReg<[XMM0]>>,
62 CCIfType<[f64], CCAssignToReg<[XMM0]>>,
Chris Lattner31c8a6d2007-02-26 18:17:14 +000063 CCDelegateTo<RetCC_X86Common>
64]>;
65
66
Chris Lattnerd50110d2007-02-27 05:51:05 +000067
68// This is the root return-value convention for the X86-32 backend.
69def RetCC_X86_32 : CallingConv<[
70 // If FastCC, use RetCC_X86_32_Fast.
Chris Lattner370bdda2007-02-28 05:30:29 +000071 CCIfCC<"CallingConv::Fast", CCDelegateTo<RetCC_X86_32_Fast>>,
Chris Lattnerd50110d2007-02-27 05:51:05 +000072 // Otherwise, use RetCC_X86_32_C.
73 CCDelegateTo<RetCC_X86_32_C>
74]>;
75
76// This is the root return-value convention for the X86-64 backend.
77def RetCC_X86_64 : CallingConv<[
78 // Always just the same as C calling conv for X86-64.
79 CCDelegateTo<RetCC_X86_64_C>
80]>;
81
Chris Lattnerd637a8b2007-02-27 06:59:52 +000082// This is the return-value convention used for the entire X86 backend.
83def RetCC_X86 : CallingConv<[
Chris Lattner370bdda2007-02-28 05:30:29 +000084 CCIfSubtarget<"is64Bit()", CCDelegateTo<RetCC_X86_64>>,
Chris Lattnerd637a8b2007-02-27 06:59:52 +000085 CCDelegateTo<RetCC_X86_32>
86]>;
Chris Lattnerd50110d2007-02-27 05:51:05 +000087
Chris Lattner31c8a6d2007-02-26 18:17:14 +000088//===----------------------------------------------------------------------===//
Chris Lattner370bdda2007-02-28 05:30:29 +000089// X86-64 Argument Calling Conventions
Chris Lattner31c8a6d2007-02-26 18:17:14 +000090//===----------------------------------------------------------------------===//
91
Chris Lattner31c8a6d2007-02-26 18:17:14 +000092def CC_X86_64_C : CallingConv<[
93 // Promote i8/i16 arguments to i32.
Chris Lattner370bdda2007-02-28 05:30:29 +000094 CCIfType<[i8, i16], CCPromoteToType<i32>>,
Chris Lattner31c8a6d2007-02-26 18:17:14 +000095
96 // The first 6 integer arguments are passed in integer registers.
Chris Lattner370bdda2007-02-28 05:30:29 +000097 CCIfType<[i32], CCAssignToReg<[EDI, ESI, EDX, ECX, R8D, R9D]>>,
98 CCIfType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8 , R9 ]>>,
Chris Lattner31c8a6d2007-02-26 18:17:14 +000099
100 // The first 8 FP/Vector arguments are passed in XMM registers.
Chris Lattner370bdda2007-02-28 05:30:29 +0000101 CCIfType<[f32, f64, v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000102 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7]>>,
103
104 // Integer/FP values get stored in stack slots that are 8 bytes in size and
105 // 8-byte aligned if there are no more registers to hold them.
Chris Lattner370bdda2007-02-28 05:30:29 +0000106 CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>,
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000107
108 // Vectors get 16-byte stack slots that are 16-byte aligned.
Bill Wendlinge2501b32007-03-30 00:35:22 +0000109 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToStack<16, 16>>,
110
111 // __m64 vectors get 8-byte stack slots that are 8-byte aligned.
112 CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToStack<8, 8>>
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000113]>;
114
115
Chris Lattner423c5f42007-02-28 05:31:48 +0000116//===----------------------------------------------------------------------===//
117// X86 C Calling Convention
118//===----------------------------------------------------------------------===//
119
Chris Lattner011bcc82007-02-28 06:20:01 +0000120/// CC_X86_32_Common - In all X86-32 calling conventions, extra integers and FP
121/// values are spilled on the stack, and the first 4 vector values go in XMM
122/// regs.
123def CC_X86_32_Common : CallingConv<[
124 // Integer/Float values get stored in stack slots that are 4 bytes in
125 // size and 4-byte aligned.
126 CCIfType<[i32, f32], CCAssignToStack<4, 4>>,
127
128 // Doubles get 8-byte slots that are 4-byte aligned.
129 CCIfType<[f64], CCAssignToStack<8, 4>>,
130
131 // The first 4 vector arguments are passed in XMM registers.
132 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
133 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3]>>,
134
135 // Other vectors get 16-byte stack slots that are 16-byte aligned.
Bill Wendlinge2501b32007-03-30 00:35:22 +0000136 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToStack<16, 16>>,
137
138 // __m64 vectors get 8-byte stack slots that are 8-byte aligned. They are
139 // passed in the parameter area.
140 CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToStack<8, 8>>
Chris Lattner011bcc82007-02-28 06:20:01 +0000141]>;
142
Chris Lattner423c5f42007-02-28 05:31:48 +0000143def CC_X86_32_C : CallingConv<[
144 // Promote i8/i16 arguments to i32.
145 CCIfType<[i8, i16], CCPromoteToType<i32>>,
146
147 // The first 3 integer arguments, if marked 'inreg', are passed in integer
148 // registers.
149 CCIfInReg<CCIfType<[i32], CCAssignToReg<[EAX, EDX, ECX]>>>,
150
Chris Lattner011bcc82007-02-28 06:20:01 +0000151 // Otherwise, same as everything else.
152 CCDelegateTo<CC_X86_32_Common>
Chris Lattner423c5f42007-02-28 05:31:48 +0000153]>;
154
155
Chris Lattner011bcc82007-02-28 06:20:01 +0000156def CC_X86_32_FastCall : CallingConv<[
157 // Promote i8/i16 arguments to i32.
158 CCIfType<[i8, i16], CCPromoteToType<i32>>,
159
160 // The first 2 integer arguments are passed in ECX/EDX
Chris Lattner70500802007-02-28 18:35:11 +0000161 CCIfType<[i32], CCAssignToReg<[ECX, EDX]>>,
Chris Lattner011bcc82007-02-28 06:20:01 +0000162
163 // Otherwise, same as everything else.
164 CCDelegateTo<CC_X86_32_Common>
165]>;
166
Chris Lattner370bdda2007-02-28 05:30:29 +0000167