blob: 635c729c9d8b29f966cb4c6c5c39a7ebeb9c00fe [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 Lattner31c8a6d2007-02-26 18:17:14 +000015//===----------------------------------------------------------------------===//
16// Return Value Calling Conventions
17//===----------------------------------------------------------------------===//
18
Chris Lattnerd50110d2007-02-27 05:51:05 +000019// Return-value conventions common to all X86 CC's.
Chris Lattner31c8a6d2007-02-26 18:17:14 +000020def 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]>>,
26
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]>>
30]>;
31
Chris Lattnerd50110d2007-02-27 05:51:05 +000032// X86-32 C return-value convention.
Chris Lattner31c8a6d2007-02-26 18:17:14 +000033def 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>
39]>;
40
Chris Lattnerd50110d2007-02-27 05:51:05 +000041// X86-32 FastCC return-value convention.
Chris Lattner31c8a6d2007-02-26 18:17:14 +000042def 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>
48]>;
49
Chris Lattnerd50110d2007-02-27 05:51:05 +000050// X86-64 C return-value convention.
Chris Lattner31c8a6d2007-02-26 18:17:14 +000051def 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>
56]>;
57
58
Chris Lattnerd50110d2007-02-27 05:51:05 +000059
60// This is the root return-value convention for the X86-32 backend.
61def 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>
66]>;
67
68// This is the root return-value convention for the X86-64 backend.
69def RetCC_X86_64 : CallingConv<[
70 // Always just the same as C calling conv for X86-64.
71 CCDelegateTo<RetCC_X86_64_C>
72]>;
73
74
75
Chris Lattner31c8a6d2007-02-26 18:17:14 +000076//===----------------------------------------------------------------------===//
77// Argument Calling Conventions
78//===----------------------------------------------------------------------===//
79
80
81def CC_X86_64_C : CallingConv<[
82 // Promote i8/i16 arguments to i32.
83 CCMatchType<[i8, i16], CCPromoteToType<i32>>,
84
85 // The first 6 integer arguments are passed in integer registers.
86 CCMatchType<[i32], CCAssignToReg<[EDI, ESI, EDX, ECX, R8D, R9D]>>,
87 CCMatchType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8 , R9 ]>>,
88
89 // The first 8 FP/Vector arguments are passed in XMM registers.
90 CCMatchType<[f32, f64, v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
91 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7]>>,
92
93 // Integer/FP values get stored in stack slots that are 8 bytes in size and
94 // 8-byte aligned if there are no more registers to hold them.
95 CCMatchType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>,
96
97 // Vectors get 16-byte stack slots that are 16-byte aligned.
98 CCMatchType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
99 CCAssignToStack<16, 16>>
100]>;
101
102