blob: ea01d1ead1ee80df0276fccf0e090eb678e419e5 [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
Bill Wendlingdb5c9932007-03-31 01:03:53 +0000104 // 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 ]>>,
107
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000108 // 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.
Chris Lattner370bdda2007-02-28 05:30:29 +0000110 CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>,
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000111
112 // Vectors get 16-byte stack slots that are 16-byte aligned.
Bill Wendlinge2501b32007-03-30 00:35:22 +0000113 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToStack<16, 16>>,
114
115 // __m64 vectors get 8-byte stack slots that are 8-byte aligned.
116 CCIfType<[v8i8, v4i16, v2i32, v1i64], CCAssignToStack<8, 8>>
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000117]>;
118
119
Chris Lattner423c5f42007-02-28 05:31:48 +0000120//===----------------------------------------------------------------------===//
121// X86 C Calling Convention
122//===----------------------------------------------------------------------===//
123
Chris Lattner011bcc82007-02-28 06:20:01 +0000124/// 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
126/// regs.
127def 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>>,
131
132 // Doubles get 8-byte slots that are 4-byte aligned.
133 CCIfType<[f64], CCAssignToStack<8, 4>>,
134
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]>>,
138
139 // Other vectors get 16-byte stack slots that are 16-byte aligned.
Bill Wendlinge2501b32007-03-30 00:35:22 +0000140 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToStack<16, 16>>,
141
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>>
Chris Lattner011bcc82007-02-28 06:20:01 +0000145]>;
146
Chris Lattner423c5f42007-02-28 05:31:48 +0000147def CC_X86_32_C : CallingConv<[
148 // Promote i8/i16 arguments to i32.
149 CCIfType<[i8, i16], CCPromoteToType<i32>>,
150
151 // The first 3 integer arguments, if marked 'inreg', are passed in integer
152 // registers.
153 CCIfInReg<CCIfType<[i32], CCAssignToReg<[EAX, EDX, ECX]>>>,
154
Chris Lattner011bcc82007-02-28 06:20:01 +0000155 // Otherwise, same as everything else.
156 CCDelegateTo<CC_X86_32_Common>
Chris Lattner423c5f42007-02-28 05:31:48 +0000157]>;
158
159
Chris Lattner011bcc82007-02-28 06:20:01 +0000160def CC_X86_32_FastCall : CallingConv<[
161 // Promote i8/i16 arguments to i32.
162 CCIfType<[i8, i16], CCPromoteToType<i32>>,
163
164 // The first 2 integer arguments are passed in ECX/EDX
Chris Lattner70500802007-02-28 18:35:11 +0000165 CCIfType<[i32], CCAssignToReg<[ECX, EDX]>>,
Chris Lattner011bcc82007-02-28 06:20:01 +0000166
167 // Otherwise, same as everything else.
168 CCDelegateTo<CC_X86_32_Common>
169]>;
170
Chris Lattner370bdda2007-02-28 05:30:29 +0000171