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 //===----------------------------------------------------------------------===//
16 // Return Value Calling Conventions
17 //===----------------------------------------------------------------------===//
19 // Return-value conventions common to all X86 CC's.
20 def RetCC_X86Common : CallingConv<[
21 // Scalar values are returned in AX first, then DX.
22 CCMatchType<[i8] , CCAssignToReg<[AL]>>,
23 CCMatchType<[i16], CCAssignToReg<[AX]>>,
24 CCMatchType<[i32], CCAssignToReg<[EAX, EDX]>>,
25 CCMatchType<[i64], CCAssignToReg<[RAX, RDX]>>,
27 // Vector types are always returned in XMM0. If the target doesn't have XMM0,
28 // it won't have vector types.
29 CCMatchType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToReg<[XMM0]>>
32 // X86-32 C return-value convention.
33 def RetCC_X86_32_C : CallingConv<[
34 // The X86-32 calling convention returns FP values in ST0, otherwise it is the
35 // same as the common X86 calling conv.
36 CCMatchType<[f32], CCAssignToReg<[ST0]>>,
37 CCMatchType<[f64], CCAssignToReg<[ST0]>>,
38 CCDelegateTo<RetCC_X86Common>
41 // X86-32 FastCC return-value convention.
42 def RetCC_X86_32_Fast : CallingConv<[
43 // The X86-32 fastcc returns FP values in XMM0 if the target has SSE2,
44 // otherwise it is the the C calling conventions.
45 CCMatchType<[f32], CCMatchIf<"Subtarget->hasSSE2()", CCAssignToReg<[XMM0]>>>,
46 CCMatchType<[f64], CCMatchIf<"Subtarget->hasSSE2()", CCAssignToReg<[XMM0]>>>,
47 CCDelegateTo<RetCC_X86Common>
50 // X86-64 C return-value convention.
51 def RetCC_X86_64_C : CallingConv<[
52 // The X86-64 calling convention always returns FP values in XMM0.
53 CCMatchType<[f32], CCAssignToReg<[XMM0]>>,
54 CCMatchType<[f64], CCAssignToReg<[XMM0]>>,
55 CCDelegateTo<RetCC_X86Common>
60 // This is the root return-value convention for the X86-32 backend.
61 def RetCC_X86_32 : CallingConv<[
62 // If FastCC, use RetCC_X86_32_Fast.
63 CCMatchIfCC<"CallingConv::Fast", CCDelegateTo<RetCC_X86_32_Fast>>,
64 // Otherwise, use RetCC_X86_32_C.
65 CCDelegateTo<RetCC_X86_32_C>
68 // This is the root return-value convention for the X86-64 backend.
69 def RetCC_X86_64 : CallingConv<[
70 // Always just the same as C calling conv for X86-64.
71 CCDelegateTo<RetCC_X86_64_C>
74 // This is the return-value convention used for the entire X86 backend.
75 def RetCC_X86 : CallingConv<[
76 CCMatchIf<"Subtarget->is64Bit()", CCDelegateTo<RetCC_X86_64>>,
77 CCDelegateTo<RetCC_X86_32>
80 //===----------------------------------------------------------------------===//
81 // Argument Calling Conventions
82 //===----------------------------------------------------------------------===//
85 def CC_X86_64_C : CallingConv<[
86 // Promote i8/i16 arguments to i32.
87 CCMatchType<[i8, i16], CCPromoteToType<i32>>,
89 // The first 6 integer arguments are passed in integer registers.
90 CCMatchType<[i32], CCAssignToReg<[EDI, ESI, EDX, ECX, R8D, R9D]>>,
91 CCMatchType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8 , R9 ]>>,
93 // The first 8 FP/Vector arguments are passed in XMM registers.
94 CCMatchType<[f32, f64, v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
95 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7]>>,
97 // Integer/FP values get stored in stack slots that are 8 bytes in size and
98 // 8-byte aligned if there are no more registers to hold them.
99 CCMatchType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>,
101 // Vectors get 16-byte stack slots that are 16-byte aligned.
102 CCMatchType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
103 CCAssignToStack<16, 16>>