blob: 110335b8c109a94ab6c8c585e89eefe0d392d3f1 [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 +000015class CCAction;
16class CallingConv;
17
Chris Lattnerd50110d2007-02-27 05:51:05 +000018/// CCPredicateAction - Instances of this class check some predicate, then
19/// delegate to another action if the predicate is true.
20class CCPredicateAction<CCAction A> : CCAction {
21 CCAction SubAction = A;
22}
Chris Lattner31c8a6d2007-02-26 18:17:14 +000023
24/// CCMatchType - If the current argument is one of the specified types, apply
25/// Action A.
Chris Lattnerd50110d2007-02-27 05:51:05 +000026class CCMatchType<list<ValueType> VTs, CCAction A> : CCPredicateAction<A> {
Chris Lattner31c8a6d2007-02-26 18:17:14 +000027}
28
29/// CCMatchIf - If the predicate matches, apply A.
Chris Lattnerd50110d2007-02-27 05:51:05 +000030class CCMatchIf<string predicate, CCAction A> : CCPredicateAction<A> {
Chris Lattner31c8a6d2007-02-26 18:17:14 +000031 string Predicate = predicate;
32}
33
Chris Lattnerd50110d2007-02-27 05:51:05 +000034/// CCMatchIfCC - Match of the current calling convention is 'CC'.
35class CCMatchIfCC<string CC, CCAction A> : CCPredicateAction<A> {
36 string CallingConv = CC;
37}
38
Chris Lattner31c8a6d2007-02-26 18:17:14 +000039/// CCAssignToReg - This action matches if there is a register in the specified
40/// list that is still available. If so, it assigns the value to the first
41/// available register and succeeds.
42class CCAssignToReg<list<Register> regList> : CCAction {
43 list<Register> RegList = regList;
44}
45
46/// CCAssignToStack - This action always matches: it assigns the value to a
47/// stack slot of the specified size and alignment on the stack.
48class CCAssignToStack<int size, int align> : CCAction {
49 int Size = size;
50 int Align = align;
51}
52
53
Chris Lattner31c8a6d2007-02-26 18:17:14 +000054/// CCPromoteToType - If applied, this promotes the specified current value to
55/// the specified type.
56class CCPromoteToType<ValueType destTy> : CCAction {
57 ValueType DestTy = destTy;
58}
59
60/// CCDelegateTo - This action invokes the specified sub-calling-convention. It
61/// is successful if the specified CC matches.
62class CCDelegateTo<CallingConv cc> : CCAction {
63 CallingConv CC = cc;
64}
65
66
67class CallingConv<list<CCAction> actions> {
68 list<CCAction> Actions = actions;
69}
70
71//===----------------------------------------------------------------------===//
72// Return Value Calling Conventions
73//===----------------------------------------------------------------------===//
74
Chris Lattnerd50110d2007-02-27 05:51:05 +000075// Return-value conventions common to all X86 CC's.
Chris Lattner31c8a6d2007-02-26 18:17:14 +000076def RetCC_X86Common : CallingConv<[
77 // Scalar values are returned in AX first, then DX.
78 CCMatchType<[i8] , CCAssignToReg<[AL]>>,
79 CCMatchType<[i16], CCAssignToReg<[AX]>>,
80 CCMatchType<[i32], CCAssignToReg<[EAX, EDX]>>,
81 CCMatchType<[i64], CCAssignToReg<[RAX, RDX]>>,
82
83 // Vector types are always returned in XMM0. If the target doesn't have XMM0,
84 // it won't have vector types.
85 CCMatchType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCAssignToReg<[XMM0]>>
86]>;
87
Chris Lattnerd50110d2007-02-27 05:51:05 +000088// X86-32 C return-value convention.
Chris Lattner31c8a6d2007-02-26 18:17:14 +000089def RetCC_X86_32_C : CallingConv<[
90 // The X86-32 calling convention returns FP values in ST0, otherwise it is the
91 // same as the common X86 calling conv.
92 CCMatchType<[f32], CCAssignToReg<[ST0]>>,
93 CCMatchType<[f64], CCAssignToReg<[ST0]>>,
94 CCDelegateTo<RetCC_X86Common>
95]>;
96
Chris Lattnerd50110d2007-02-27 05:51:05 +000097// X86-32 FastCC return-value convention.
Chris Lattner31c8a6d2007-02-26 18:17:14 +000098def RetCC_X86_32_Fast : CallingConv<[
99 // The X86-32 fastcc returns FP values in XMM0 if the target has SSE2,
100 // otherwise it is the the C calling conventions.
101 CCMatchType<[f32], CCMatchIf<"Subtarget->hasSSE2()", CCAssignToReg<[XMM0]>>>,
102 CCMatchType<[f64], CCMatchIf<"Subtarget->hasSSE2()", CCAssignToReg<[XMM0]>>>,
103 CCDelegateTo<RetCC_X86Common>
104]>;
105
Chris Lattnerd50110d2007-02-27 05:51:05 +0000106// X86-64 C return-value convention.
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000107def RetCC_X86_64_C : CallingConv<[
108 // The X86-64 calling convention always returns FP values in XMM0.
109 CCMatchType<[f32], CCAssignToReg<[XMM0]>>,
110 CCMatchType<[f64], CCAssignToReg<[XMM0]>>,
111 CCDelegateTo<RetCC_X86Common>
112]>;
113
114
Chris Lattnerd50110d2007-02-27 05:51:05 +0000115
116// This is the root return-value convention for the X86-32 backend.
117def RetCC_X86_32 : CallingConv<[
118 // If FastCC, use RetCC_X86_32_Fast.
119 CCMatchIfCC<"CallingConv::Fast", CCDelegateTo<RetCC_X86_32_Fast>>,
120 // Otherwise, use RetCC_X86_32_C.
121 CCDelegateTo<RetCC_X86_32_C>
122]>;
123
124// This is the root return-value convention for the X86-64 backend.
125def RetCC_X86_64 : CallingConv<[
126 // Always just the same as C calling conv for X86-64.
127 CCDelegateTo<RetCC_X86_64_C>
128]>;
129
130
131
Chris Lattner31c8a6d2007-02-26 18:17:14 +0000132//===----------------------------------------------------------------------===//
133// Argument Calling Conventions
134//===----------------------------------------------------------------------===//
135
136
137def CC_X86_64_C : CallingConv<[
138 // Promote i8/i16 arguments to i32.
139 CCMatchType<[i8, i16], CCPromoteToType<i32>>,
140
141 // The first 6 integer arguments are passed in integer registers.
142 CCMatchType<[i32], CCAssignToReg<[EDI, ESI, EDX, ECX, R8D, R9D]>>,
143 CCMatchType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8 , R9 ]>>,
144
145 // The first 8 FP/Vector arguments are passed in XMM registers.
146 CCMatchType<[f32, f64, v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
147 CCAssignToReg<[XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7]>>,
148
149 // Integer/FP values get stored in stack slots that are 8 bytes in size and
150 // 8-byte aligned if there are no more registers to hold them.
151 CCMatchType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>,
152
153 // Vectors get 16-byte stack slots that are 16-byte aligned.
154 CCMatchType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
155 CCAssignToStack<16, 16>>
156]>;
157
158