fill in some holes
[oota-llvm.git] / lib / Target / X86 / X86CallingConv.td
1 //===- X86CallingConv.td - Calling Conventions for X86 32/64 ----*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
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.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This describes the calling conventions for the X86-32 and X86-64
11 // architectures.
12 //
13 //===----------------------------------------------------------------------===//
14
15 class CCAction;
16 class CallingConv;
17
18 /// CCPredicateAction - Instances of this class check some predicate, then
19 /// delegate to another action if the predicate is true.
20 class CCPredicateAction<CCAction A> : CCAction {
21   CCAction SubAction = A;
22 }
23
24 /// CCMatchType - If the current argument is one of the specified types, apply
25 /// Action A.
26 class CCMatchType<list<ValueType> VTs, CCAction A> : CCPredicateAction<A> {
27 }
28
29 /// CCMatchIf - If the predicate matches, apply A.
30 class CCMatchIf<string predicate, CCAction A> : CCPredicateAction<A> {
31   string Predicate = predicate;
32 }
33
34 /// CCMatchIfCC - Match of the current calling convention is 'CC'.
35 class CCMatchIfCC<string CC, CCAction A> : CCPredicateAction<A> {
36   string CallingConv = CC;
37 }
38
39 /// 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.
42 class 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.
48 class CCAssignToStack<int size, int align> : CCAction {
49   int Size = size;
50   int Align = align;
51 }
52
53
54 /// CCPromoteToType - If applied, this promotes the specified current value to
55 /// the specified type.
56 class 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.
62 class CCDelegateTo<CallingConv cc> : CCAction {
63   CallingConv CC = cc;
64 }
65
66
67 class CallingConv<list<CCAction> actions> {
68   list<CCAction> Actions = actions;
69 }
70
71 //===----------------------------------------------------------------------===//
72 // Return Value Calling Conventions
73 //===----------------------------------------------------------------------===//
74
75 // Return-value conventions common to all X86 CC's.
76 def 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
88 // X86-32 C return-value convention.
89 def 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
97 // X86-32 FastCC return-value convention.
98 def 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
106 // X86-64 C return-value convention.
107 def 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
115
116 // This is the root return-value convention for the X86-32 backend.
117 def 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.
125 def 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
132 //===----------------------------------------------------------------------===//
133 // Argument Calling Conventions
134 //===----------------------------------------------------------------------===//
135
136
137 def 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