blob: 079313b8cc35434151b6b1450da82b0dd1ca0c2a [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 Lattner3d559102007-02-28 04:51:41 +000015/// CCMatchIfSubtarget - Match if the current subtarget has a feature F.
16class CCMatchIfSubtarget<string F, CCAction A>
17 : CCMatchIf<!strconcat("State.getTarget().getSubtarget<X86Subtarget>().",F),A>;
18
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.
26 CCMatchType<[i8] , CCAssignToReg<[AL]>>,
27 CCMatchType<[i16], CCAssignToReg<[AX]>>,
28 CCMatchType<[i32], CCAssignToReg<[EAX, EDX]>>,
29 CCMatchType<[i64], CCAssignToReg<[RAX, RDX]>>,
30
31 // Vector types are always returned in XMM0. If the target doesn't have XMM0,
32 // it won't have vector types.
33 CCMatchType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToReg<[XMM0]>>
34]>;
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.
40 CCMatchType<[f32], CCAssignToReg<[ST0]>>,
41 CCMatchType<[f64], CCAssignToReg<[ST0]>>,
42 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 Lattner3d559102007-02-28 04:51:41 +000049 CCMatchType<[f32], CCMatchIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0]>>>,
50 CCMatchType<[f64], CCMatchIfSubtarget<"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.
57 CCMatchType<[f32], CCAssignToReg<[XMM0]>>,
58 CCMatchType<[f64], CCAssignToReg<[XMM0]>>,
59 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.
67 CCMatchIfCC<"CallingConv::Fast", CCDelegateTo<RetCC_X86_32_Fast>>,
68 // 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 Lattner3d559102007-02-28 04:51:41 +000080 CCMatchIfSubtarget<"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//===----------------------------------------------------------------------===//
85// Argument Calling Conventions
86//===----------------------------------------------------------------------===//
87
88
89def CC_X86_64_C : CallingConv<[
90 // Promote i8/i16 arguments to i32.
91 CCMatchType<[i8, i16], CCPromoteToType<i32>>,
92
93 // The first 6 integer arguments are passed in integer registers.
94 CCMatchType<[i32], CCAssignToReg<[EDI, ESI, EDX, ECX, R8D, R9D]>>,
95 CCMatchType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8 , R9 ]>>,
96
97 // The first 8 FP/Vector arguments are passed in XMM registers.
98 CCMatchType<[f32, f64, v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
99 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7]>>,
100
101 // Integer/FP values get stored in stack slots that are 8 bytes in size and
102 // 8-byte aligned if there are no more registers to hold them.
103 CCMatchType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>,
104
105 // Vectors get 16-byte stack slots that are 16-byte aligned.
106 CCMatchType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
107 CCAssignToStack<16, 16>>
108]>;
109
110