blob: 04a79043fdf19cca27e8bb10fa1d33a3580f0ee2 [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
114def CC_X86_32_C : CallingConv<[
115 // Promote i8/i16 arguments to i32.
116 CCIfType<[i8, i16], CCPromoteToType<i32>>,
117
118 // The first 3 integer arguments, if marked 'inreg', are passed in integer
119 // registers.
120 CCIfInReg<CCIfType<[i32], CCAssignToReg<[EAX, EDX, ECX]>>>,
121
122 // Other Integer/Float values get stored in stack slots that are 4 bytes in
123 // size and 4-byte aligned.
124 CCIfType<[i32, f32], CCAssignToStack<4, 4>>,
125
126 // Doubles get 8-byte slots that are 4-byte aligned.
127 CCIfType<[f64], CCAssignToStack<8, 4>>,
128
129 // The first 4 Vector arguments are passed in XMM registers.
130 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
131 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3]>>,
132
133 // Other vectors get 16-byte stack slots that are 16-byte aligned.
134 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToStack<16, 16>>
135]>;
136
137
Chris Lattner370bdda2007-02-28 05:30:29 +0000138