1 //===- X86CallingConv.td - Calling Conventions for X86 32/64 ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Chris Lattner and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This describes the calling conventions for the X86-32 and X86-64
13 //===----------------------------------------------------------------------===//
15 /// CCMatchIfSubtarget - Match if the current subtarget has a feature F.
16 class CCMatchIfSubtarget<string F, CCAction A>
17 : CCMatchIf<!strconcat("State.getTarget().getSubtarget<X86Subtarget>().",F),A>;
19 //===----------------------------------------------------------------------===//
20 // Return Value Calling Conventions
21 //===----------------------------------------------------------------------===//
23 // Return-value conventions common to all X86 CC's.
24 def 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]>>,
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]>>
36 // X86-32 C return-value convention.
37 def 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>
45 // X86-32 FastCC return-value convention.
46 def 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.
49 CCMatchType<[f32], CCMatchIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0]>>>,
50 CCMatchType<[f64], CCMatchIfSubtarget<"hasSSE2()", CCAssignToReg<[XMM0]>>>,
51 CCDelegateTo<RetCC_X86Common>
54 // X86-64 C return-value convention.
55 def 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>
64 // This is the root return-value convention for the X86-32 backend.
65 def 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>
72 // This is the root return-value convention for the X86-64 backend.
73 def RetCC_X86_64 : CallingConv<[
74 // Always just the same as C calling conv for X86-64.
75 CCDelegateTo<RetCC_X86_64_C>
78 // This is the return-value convention used for the entire X86 backend.
79 def RetCC_X86 : CallingConv<[
80 CCMatchIfSubtarget<"is64Bit()", CCDelegateTo<RetCC_X86_64>>,
81 CCDelegateTo<RetCC_X86_32>
84 //===----------------------------------------------------------------------===//
85 // Argument Calling Conventions
86 //===----------------------------------------------------------------------===//
89 def CC_X86_64_C : CallingConv<[
90 // Promote i8/i16 arguments to i32.
91 CCMatchType<[i8, i16], CCPromoteToType<i32>>,
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 ]>>,
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]>>,
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>>,
105 // Vectors get 16-byte stack slots that are 16-byte aligned.
106 CCMatchType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
107 CCAssignToStack<16, 16>>