blob: d397bf3369f1f665336b42ecf5fb2cb5374da7b1 [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.
Chris Lattner370bdda2007-02-28 05:30:29 +000033 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToReg<[XMM0]>>
Chris Lattner31c8a6d2007-02-26 18:17:14 +000034]>;
35
Chris Lattnerd50110d2007-02-27 05:51:05 +000036// X86-32 C return-value convention.
Chris Lattner31c8a6d2007-02-26 18:17:14 +000037def RetCC_X86_32_C : CallingConv<[
38 // The X86-32 calling convention returns FP values in ST0, otherwise it is the
39 // same as the common X86 calling conv.
Chris Lattner370bdda2007-02-28 05:30:29 +000040 CCIfType<[f32], CCAssignToReg<[ST0]>>,
41 CCIfType<[f64], CCAssignToReg<[ST0]>>,
Chris Lattner31c8a6d2007-02-26 18:17:14 +000042 CCDelegateTo<RetCC_X86Common>
43]>;
44
Chris Lattnerd50110d2007-02-27 05:51:05 +000045// X86-32 FastCC return-value convention.
Chris Lattner31c8a6d2007-02-26 18:17:14 +000046def RetCC_X86_32_Fast : CallingConv<[
47 // The X86-32 fastcc returns FP values in XMM0 if the target has SSE2,
48 // otherwise it is the the C calling conventions.
Chris Lattner370bdda2007-02-28 05:30:29 +000049 CCIfType<[f32], CCIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0]>>>,
50 CCIfType<[f64], CCIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0]>>>,
Chris Lattner31c8a6d2007-02-26 18:17:14 +000051 CCDelegateTo<RetCC_X86Common>
52]>;
53
Chris Lattnerd50110d2007-02-27 05:51:05 +000054// X86-64 C return-value convention.
Chris Lattner31c8a6d2007-02-26 18:17:14 +000055def RetCC_X86_64_C : CallingConv<[
56 // The X86-64 calling convention always returns FP values in XMM0.
Chris Lattner370bdda2007-02-28 05:30:29 +000057 CCIfType<[f32], CCAssignToReg<[XMM0]>>,
58 CCIfType<[f64], CCAssignToReg<[XMM0]>>,
Chris Lattner31c8a6d2007-02-26 18:17:14 +000059 CCDelegateTo<RetCC_X86Common>
60]>;
61
62
Chris Lattnerd50110d2007-02-27 05:51:05 +000063
64// This is the root return-value convention for the X86-32 backend.
65def RetCC_X86_32 : CallingConv<[
66 // If FastCC, use RetCC_X86_32_Fast.
Chris Lattner370bdda2007-02-28 05:30:29 +000067 CCIfCC<"CallingConv::Fast", CCDelegateTo<RetCC_X86_32_Fast>>,
Chris Lattnerd50110d2007-02-27 05:51:05 +000068 // Otherwise, use RetCC_X86_32_C.
69 CCDelegateTo<RetCC_X86_32_C>
70]>;
71
72// This is the root return-value convention for the X86-64 backend.
73def RetCC_X86_64 : CallingConv<[
74 // Always just the same as C calling conv for X86-64.
75 CCDelegateTo<RetCC_X86_64_C>
76]>;
77
Chris Lattnerd637a8b2007-02-27 06:59:52 +000078// This is the return-value convention used for the entire X86 backend.
79def RetCC_X86 : CallingConv<[
Chris Lattner370bdda2007-02-28 05:30:29 +000080 CCIfSubtarget<"is64Bit()", CCDelegateTo<RetCC_X86_64>>,
Chris Lattnerd637a8b2007-02-27 06:59:52 +000081 CCDelegateTo<RetCC_X86_32>
82]>;
Chris Lattnerd50110d2007-02-27 05:51:05 +000083
Chris Lattner31c8a6d2007-02-26 18:17:14 +000084//===----------------------------------------------------------------------===//
Chris Lattner370bdda2007-02-28 05:30:29 +000085// X86-64 Argument Calling Conventions
Chris Lattner31c8a6d2007-02-26 18:17:14 +000086//===----------------------------------------------------------------------===//
87
Chris Lattner31c8a6d2007-02-26 18:17:14 +000088def CC_X86_64_C : CallingConv<[
89 // Promote i8/i16 arguments to i32.
Chris Lattner370bdda2007-02-28 05:30:29 +000090 CCIfType<[i8, i16], CCPromoteToType<i32>>,
Chris Lattner31c8a6d2007-02-26 18:17:14 +000091
92 // The first 6 integer arguments are passed in integer registers.
Chris Lattner370bdda2007-02-28 05:30:29 +000093 CCIfType<[i32], CCAssignToReg<[EDI, ESI, EDX, ECX, R8D, R9D]>>,
94 CCIfType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8 , R9 ]>>,
Chris Lattner31c8a6d2007-02-26 18:17:14 +000095
96 // The first 8 FP/Vector arguments are passed in XMM registers.
Chris Lattner370bdda2007-02-28 05:30:29 +000097 CCIfType<[f32, f64, v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
Chris Lattner31c8a6d2007-02-26 18:17:14 +000098 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7]>>,
99
100 // Integer/FP values get stored in stack slots that are 8 bytes in size and
101 // 8-byte aligned if there are no more registers to hold them.
Chris Lattner370bdda2007-02-28 05:30:29 +0000102 CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>,
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000103
104 // Vectors get 16-byte stack slots that are 16-byte aligned.
Chris Lattner370bdda2007-02-28 05:30:29 +0000105 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000106 CCAssignToStack<16, 16>>
107]>;
108
109
Chris Lattner423c5f42007-02-28 05:31:48 +0000110//===----------------------------------------------------------------------===//
111// X86 C Calling Convention
112//===----------------------------------------------------------------------===//
113
Chris Lattner011bcc82007-02-28 06:20:01 +0000114/// CC_X86_32_Common - In all X86-32 calling conventions, extra integers and FP
115/// values are spilled on the stack, and the first 4 vector values go in XMM
116/// regs.
117def CC_X86_32_Common : CallingConv<[
118 // Integer/Float values get stored in stack slots that are 4 bytes in
119 // size and 4-byte aligned.
120 CCIfType<[i32, f32], CCAssignToStack<4, 4>>,
121
122 // Doubles get 8-byte slots that are 4-byte aligned.
123 CCIfType<[f64], CCAssignToStack<8, 4>>,
124
125 // The first 4 vector arguments are passed in XMM registers.
126 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
127 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3]>>,
128
129 // Other vectors get 16-byte stack slots that are 16-byte aligned.
130 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToStack<16, 16>>
131]>;
132
Chris Lattner423c5f42007-02-28 05:31:48 +0000133def CC_X86_32_C : CallingConv<[
134 // Promote i8/i16 arguments to i32.
135 CCIfType<[i8, i16], CCPromoteToType<i32>>,
136
137 // The first 3 integer arguments, if marked 'inreg', are passed in integer
138 // registers.
139 CCIfInReg<CCIfType<[i32], CCAssignToReg<[EAX, EDX, ECX]>>>,
140
Chris Lattner011bcc82007-02-28 06:20:01 +0000141 // Otherwise, same as everything else.
142 CCDelegateTo<CC_X86_32_Common>
Chris Lattner423c5f42007-02-28 05:31:48 +0000143]>;
144
145
Chris Lattner011bcc82007-02-28 06:20:01 +0000146def CC_X86_32_FastCall : CallingConv<[
147 // Promote i8/i16 arguments to i32.
148 CCIfType<[i8, i16], CCPromoteToType<i32>>,
149
150 // The first 2 integer arguments are passed in ECX/EDX
Chris Lattner70500802007-02-28 18:35:11 +0000151 CCIfType<[i32], CCAssignToReg<[ECX, EDX]>>,
Chris Lattner011bcc82007-02-28 06:20:01 +0000152
153 // Otherwise, same as everything else.
154 CCDelegateTo<CC_X86_32_Common>
155]>;
156
Chris Lattner370bdda2007-02-28 05:30:29 +0000157