blob: ac40b118004c7c6cf9e6e77dd52bf390553169a5 [file] [log] [blame]
Jia Liubb481f82012-02-28 07:46:26 +00001//===-- MipsCallingConv.td - Calling Conventions for Mips --*- tablegen -*-===//
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +00002//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +00007//
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00008//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00009// This describes the calling conventions for Mips architecture.
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000010//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000011
12/// CCIfSubtarget - Match if the current subtarget has a feature F.
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +000013class CCIfSubtarget<string F, CCAction A>:
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000014 CCIf<!strconcat("State.getTarget().getSubtarget<MipsSubtarget>().", F), A>;
15
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000016//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000017// Mips O32 Calling Convention
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000018//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000019
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +000020// Only the return rules are defined here for O32. The rules for argument
Bruno Cardoso Lopesb53db4f2009-03-19 02:12:28 +000021// passing are defined in MipsISelLowering.cpp.
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000022def RetCC_MipsO32 : CallingConv<[
Akira Hatanaka805569f2011-06-21 01:28:11 +000023 // i32 are returned in registers V0, V1, A0, A1
24 CCIfType<[i32], CCAssignToReg<[V0, V1, A0, A1]>>,
Bruno Cardoso Lopes64cf1602008-08-03 15:37:43 +000025
Bruno Cardoso Lopese5ebd5f2010-01-19 12:37:35 +000026 // f32 are returned in registers F0, F2
27 CCIfType<[f32], CCAssignToReg<[F0, F2]>>,
Bruno Cardoso Lopes64cf1602008-08-03 15:37:43 +000028
Bruno Cardoso Lopese5ebd5f2010-01-19 12:37:35 +000029 // f64 are returned in register D0, D1
30 CCIfType<[f64], CCIfSubtarget<"isNotSingleFloat()", CCAssignToReg<[D0, D1]>>>
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000031]>;
32
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000033//===----------------------------------------------------------------------===//
Akira Hatanaka45b73e22011-09-23 19:08:15 +000034// Mips N32/64 Calling Convention
35//===----------------------------------------------------------------------===//
36
37def CC_MipsN : CallingConv<[
Akira Hatanaka38bdc572012-02-17 02:20:26 +000038 // Promote i8/i16 arguments to i32.
39 CCIfType<[i8, i16], CCPromoteToType<i32>>,
Akira Hatanaka45b73e22011-09-23 19:08:15 +000040
41 // Integer arguments are passed in integer registers.
Akira Hatanaka38bdc572012-02-17 02:20:26 +000042 CCIfType<[i32], CCAssignToRegWithShadow<[A0, A1, A2, A3,
43 T0, T1, T2, T3],
44 [F12, F13, F14, F15,
45 F16, F17, F18, F19]>>,
46
Akira Hatanaka45b73e22011-09-23 19:08:15 +000047 CCIfType<[i64], CCAssignToRegWithShadow<[A0_64, A1_64, A2_64, A3_64,
48 T0_64, T1_64, T2_64, T3_64],
49 [D12_64, D13_64, D14_64, D15_64,
50 D16_64, D17_64, D18_64, D19_64]>>,
51
52 // f32 arguments are passed in single precision FP registers.
53 CCIfType<[f32], CCAssignToRegWithShadow<[F12, F13, F14, F15,
54 F16, F17, F18, F19],
55 [A0_64, A1_64, A2_64, A3_64,
56 T0_64, T1_64, T2_64, T3_64]>>,
57
58 // f64 arguments are passed in double precision FP registers.
59 CCIfType<[f64], CCAssignToRegWithShadow<[D12_64, D13_64, D14_64, D15_64,
60 D16_64, D17_64, D18_64, D19_64],
61 [A0_64, A1_64, A2_64, A3_64,
62 T0_64, T1_64, T2_64, T3_64]>>,
63
64 // All stack parameter slots become 64-bit doublewords and are 8-byte aligned.
Akira Hatanaka38bdc572012-02-17 02:20:26 +000065 CCIfType<[i32, f32], CCAssignToStack<4, 8>>,
66 CCIfType<[i64, f64], CCAssignToStack<8, 8>>
Akira Hatanaka45b73e22011-09-23 19:08:15 +000067]>;
68
Akira Hatanaka49617092011-11-14 19:02:54 +000069// N32/64 variable arguments.
70// All arguments are passed in integer registers.
71def CC_MipsN_VarArg : CallingConv<[
Akira Hatanaka38bdc572012-02-17 02:20:26 +000072 // Promote i8/i16 arguments to i32.
73 CCIfType<[i8, i16], CCPromoteToType<i32>>,
74
75 CCIfType<[i32, f32], CCAssignToReg<[A0, A1, A2, A3, T0, T1, T2, T3]>>,
Akira Hatanaka49617092011-11-14 19:02:54 +000076
77 CCIfType<[i64, f64], CCAssignToReg<[A0_64, A1_64, A2_64, A3_64,
78 T0_64, T1_64, T2_64, T3_64]>>,
79
Akira Hatanaka49617092011-11-14 19:02:54 +000080 // All stack parameter slots become 64-bit doublewords and are 8-byte aligned.
Akira Hatanaka38bdc572012-02-17 02:20:26 +000081 CCIfType<[i32, f32], CCAssignToStack<4, 8>>,
82 CCIfType<[i64, f64], CCAssignToStack<8, 8>>
Akira Hatanaka49617092011-11-14 19:02:54 +000083]>;
84
Akira Hatanaka45b73e22011-09-23 19:08:15 +000085def RetCC_MipsN : CallingConv<[
Akira Hatanaka45b73e22011-09-23 19:08:15 +000086 // i32 are returned in registers V0, V1
87 CCIfType<[i32], CCAssignToReg<[V0, V1]>>,
88
89 // i64 are returned in registers V0_64, V1_64
90 CCIfType<[i64], CCAssignToReg<[V0_64, V1_64]>>,
91
92 // f32 are returned in registers F0, F2
93 CCIfType<[f32], CCAssignToReg<[F0, F2]>>,
94
95 // f64 are returned in registers D0, D2
96 CCIfType<[f64], CCAssignToReg<[D0_64, D2_64]>>
97]>;
98
Akira Hatanaka1e3e8692013-03-05 22:54:59 +000099// In soft-mode, register A0_64, instead of V1_64, is used to return a long
100// double value.
101def RetCC_F128Soft : CallingConv<[
102 CCIfType<[i64], CCAssignToReg<[V0_64, A0_64]>>
103]>;
104
Akira Hatanaka45b73e22011-09-23 19:08:15 +0000105//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000106// Mips EABI Calling Convention
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000107//===----------------------------------------------------------------------===//
Bruno Cardoso Lopesb53db4f2009-03-19 02:12:28 +0000108
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000109def CC_MipsEABI : CallingConv<[
110 // Promote i8/i16 arguments to i32.
111 CCIfType<[i8, i16], CCPromoteToType<i32>>,
112
113 // Integer arguments are passed in integer registers.
114 CCIfType<[i32], CCAssignToReg<[A0, A1, A2, A3, T0, T1, T2, T3]>>,
115
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000116 // Single fp arguments are passed in pairs within 32-bit mode
117 CCIfType<[f32], CCIfSubtarget<"isSingleFloat()",
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000118 CCAssignToReg<[F12, F13, F14, F15, F16, F17, F18, F19]>>>,
119
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000120 CCIfType<[f32], CCIfSubtarget<"isNotSingleFloat()",
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000121 CCAssignToReg<[F12, F14, F16, F18]>>>,
122
Duncan Sandsd03bcc12011-04-25 06:21:43 +0000123 // The first 4 double fp arguments are passed in single fp registers.
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000124 CCIfType<[f64], CCIfSubtarget<"isNotSingleFloat()",
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000125 CCAssignToReg<[D6, D7, D8, D9]>>>,
126
127 // Integer values get stored in stack slots that are 4 bytes in
128 // size and 4-byte aligned.
129 CCIfType<[i32, f32], CCAssignToStack<4, 4>>,
130
131 // Integer values get stored in stack slots that are 8 bytes in
132 // size and 8-byte aligned.
133 CCIfType<[f64], CCIfSubtarget<"isNotSingleFloat()", CCAssignToStack<8, 8>>>
134]>;
135
136def RetCC_MipsEABI : CallingConv<[
137 // i32 are returned in registers V0, V1
138 CCIfType<[i32], CCAssignToReg<[V0, V1]>>,
139
140 // f32 are returned in registers F0, F1
141 CCIfType<[f32], CCAssignToReg<[F0, F1]>>,
142
143 // f64 are returned in register D0
144 CCIfType<[f64], CCIfSubtarget<"isNotSingleFloat()", CCAssignToReg<[D0]>>>
145]>;
146
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000147//===----------------------------------------------------------------------===//
Akira Hatanaka777a1202012-06-13 18:06:00 +0000148// Mips FastCC Calling Convention
149//===----------------------------------------------------------------------===//
150def CC_MipsO32_FastCC : CallingConv<[
151 // f64 arguments are passed in double-precision floating pointer registers.
152 CCIfType<[f64], CCAssignToReg<[D0, D1, D2, D3, D4, D5, D6, D7, D8, D9]>>,
153
154 // Stack parameter slots for f64 are 64-bit doublewords and 8-byte aligned.
155 CCIfType<[f64], CCAssignToStack<8, 8>>
156]>;
157
158def CC_MipsN_FastCC : CallingConv<[
159 // Integer arguments are passed in integer registers.
160 CCIfType<[i64], CCAssignToReg<[A0_64, A1_64, A2_64, A3_64, T0_64, T1_64,
161 T2_64, T3_64, T4_64, T5_64, T6_64, T7_64,
162 T8_64, V1_64]>>,
163
164 // f64 arguments are passed in double-precision floating pointer registers.
165 CCIfType<[f64], CCAssignToReg<[D0_64, D1_64, D2_64, D3_64, D4_64, D5_64,
166 D6_64, D7_64, D8_64, D9_64, D10_64, D11_64,
167 D12_64, D13_64, D14_64, D15_64, D16_64, D17_64,
168 D18_64, D19_64]>>,
169
170 // Stack parameter slots for i64 and f64 are 64-bit doublewords and
171 // 8-byte aligned.
172 CCIfType<[i64, f64], CCAssignToStack<8, 8>>
173]>;
174
175def CC_Mips_FastCC : CallingConv<[
176 // Handles byval parameters.
177 CCIfByVal<CCPassByVal<4, 4>>,
178
179 // Promote i8/i16 arguments to i32.
180 CCIfType<[i8, i16], CCPromoteToType<i32>>,
181
182 // Integer arguments are passed in integer registers. All scratch registers,
183 // except for AT, V0 and T9, are available to be used as argument registers.
184 CCIfType<[i32], CCAssignToReg<[A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6,
185 T7, T8, V1]>>,
186
187 // f32 arguments are passed in single-precision floating pointer registers.
188 CCIfType<[f32], CCAssignToReg<[F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10,
189 F11, F12, F13, F14, F15, F16, F17, F18, F19]>>,
190
191 // Stack parameter slots for i32 and f32 are 32-bit words and 4-byte aligned.
192 CCIfType<[i32, f32], CCAssignToStack<4, 4>>,
193
194 CCIfSubtarget<"isABI_EABI()", CCDelegateTo<CC_MipsEABI>>,
195 CCIfSubtarget<"isABI_O32()", CCDelegateTo<CC_MipsO32_FastCC>>,
196 CCDelegateTo<CC_MipsN_FastCC>
197]>;
198
Reed Kotler46090912013-05-10 22:25:39 +0000199//==
200
201def CC_Mips16RetHelper : CallingConv<[
202 // Integer arguments are passed in integer registers.
203 CCIfType<[i32], CCAssignToReg<[V0, V1, A0, A1]>>
204]>;
205
Akira Hatanaka777a1202012-06-13 18:06:00 +0000206//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000207// Mips Calling Convention Dispatch
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000208//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000209
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000210def RetCC_Mips : CallingConv<[
211 CCIfSubtarget<"isABI_EABI()", CCDelegateTo<RetCC_MipsEABI>>,
Akira Hatanaka45b73e22011-09-23 19:08:15 +0000212 CCIfSubtarget<"isABI_N32()", CCDelegateTo<RetCC_MipsN>>,
213 CCIfSubtarget<"isABI_N64()", CCDelegateTo<RetCC_MipsN>>,
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000214 CCDelegateTo<RetCC_MipsO32>
215]>;
Akira Hatanakab2930b92012-03-01 22:27:29 +0000216
217//===----------------------------------------------------------------------===//
218// Callee-saved register lists.
219//===----------------------------------------------------------------------===//
220
221def CSR_SingleFloatOnly : CalleeSavedRegs<(add (sequence "F%u", 31, 20), RA, FP,
222 (sequence "S%u", 7, 0))>;
223
224def CSR_O32 : CalleeSavedRegs<(add (sequence "D%u", 15, 10), RA, FP,
225 (sequence "S%u", 7, 0))>;
226
227def CSR_N32 : CalleeSavedRegs<(add D31_64, D29_64, D27_64, D25_64, D24_64,
228 D23_64, D22_64, D21_64, RA_64, FP_64, GP_64,
229 (sequence "S%u_64", 7, 0))>;
230
231def CSR_N64 : CalleeSavedRegs<(add (sequence "D%u_64", 31, 24), RA_64, FP_64,
232 GP_64, (sequence "S%u_64", 7, 0))>;
Reed Kotler46090912013-05-10 22:25:39 +0000233
Jack Carterd7610042013-05-16 20:08:49 +0000234def CSR_Mips16RetHelper :
Reed Kotler46090912013-05-10 22:25:39 +0000235 CalleeSavedRegs<(add V0, V1, (sequence "A%u", 3, 0), S0, S1)>;