blob: 9e47338f09a6982dc6cfd2f219dedccfbbc95f27 [file] [log] [blame]
Jia Liuf54f60f2012-02-28 07:46:26 +00001//===-- MipsCallingConv.td - Calling Conventions for Mips --*- tablegen -*-===//
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +00002//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-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 Lopesed874ef2011-03-04 17:51:39 +00007//
Akira Hatanakae2489122011-04-15 21:51:11 +00008//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +00009// This describes the calling conventions for Mips architecture.
Akira Hatanakae2489122011-04-15 21:51:11 +000010//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000011
12/// CCIfSubtarget - Match if the current subtarget has a feature F.
Daniel Sanders24b65722014-09-10 12:02:27 +000013class CCIfSubtarget<string F, CCAction A, string Invert = "">
14 : CCIf<!strconcat(Invert,
15 "static_cast<const MipsSubtarget&>"
Eric Christopherb5217502014-08-06 18:45:26 +000016 "(State.getMachineFunction().getSubtarget()).",
17 F),
18 A>;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000019
Daniel Sanders24b65722014-09-10 12:02:27 +000020// The inverse of CCIfSubtarget
21class CCIfSubtargetNot<string F, CCAction A> : CCIfSubtarget<F, A, "!">;
22
Daniel Sandersb3ca3382014-09-26 10:06:12 +000023// For soft-float, f128 values are returned in A0_64 rather than V1_64.
24def RetCC_F128SoftFloat : CallingConv<[
25 CCAssignToReg<[V0_64, A0_64]>
26]>;
27
28// For hard-float, f128 values are returned as a pair of f64's rather than a
29// pair of i64's.
30def RetCC_F128HardFloat : CallingConv<[
31 CCBitConvertToType<f64>,
Daniel Sandersf3fe49a2014-10-07 09:29:59 +000032
33 // Contrary to the ABI documentation, a struct containing a long double is
34 // returned in $f0, and $f1 instead of the usual $f0, and $f2. This is to
35 // match the de facto ABI as implemented by GCC.
36 CCIfInReg<CCAssignToReg<[D0_64, D1_64]>>,
37
Daniel Sandersb3ca3382014-09-26 10:06:12 +000038 CCAssignToReg<[D0_64, D2_64]>
39]>;
40
41// Handle F128 specially since we can't identify the original type during the
42// tablegen-erated code.
43def RetCC_F128 : CallingConv<[
44 CCIfSubtarget<"abiUsesSoftFloat()",
45 CCIfType<[i64], CCDelegateTo<RetCC_F128SoftFloat>>>,
46 CCIfSubtargetNot<"abiUsesSoftFloat()",
47 CCIfType<[i64], CCDelegateTo<RetCC_F128HardFloat>>>
48]>;
49
Akira Hatanakae2489122011-04-15 21:51:11 +000050//===----------------------------------------------------------------------===//
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +000051// Mips O32 Calling Convention
Akira Hatanakae2489122011-04-15 21:51:11 +000052//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000053
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +000054// Only the return rules are defined here for O32. The rules for argument
Bruno Cardoso Lopes3b7b3012009-03-19 02:12:28 +000055// passing are defined in MipsISelLowering.cpp.
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +000056def RetCC_MipsO32 : CallingConv<[
Akira Hatanaka27029882011-06-21 01:28:11 +000057 // i32 are returned in registers V0, V1, A0, A1
58 CCIfType<[i32], CCAssignToReg<[V0, V1, A0, A1]>>,
Bruno Cardoso Lopes3e667cf2008-08-03 15:37:43 +000059
Bruno Cardoso Lopes2f5c8e32010-01-19 12:37:35 +000060 // f32 are returned in registers F0, F2
61 CCIfType<[f32], CCAssignToReg<[F0, F2]>>,
Bruno Cardoso Lopes3e667cf2008-08-03 15:37:43 +000062
Zoran Jovanovicf34b4542014-07-10 22:23:30 +000063 // f64 arguments are returned in D0_64 and D2_64 in FP64bit mode or
Akira Hatanakabfb66242013-08-20 23:38:40 +000064 // in D0 and D1 in FP32bit mode.
Zoran Jovanovicf34b4542014-07-10 22:23:30 +000065 CCIfType<[f64], CCIfSubtarget<"isFP64bit()", CCAssignToReg<[D0_64, D2_64]>>>,
Daniel Sanders24b65722014-09-10 12:02:27 +000066 CCIfType<[f64], CCIfSubtargetNot<"isFP64bit()", CCAssignToReg<[D0, D1]>>>
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +000067]>;
68
Akira Hatanakae2489122011-04-15 21:51:11 +000069//===----------------------------------------------------------------------===//
Akira Hatanakad6af2c62011-09-23 19:08:15 +000070// Mips N32/64 Calling Convention
71//===----------------------------------------------------------------------===//
72
73def CC_MipsN : CallingConv<[
Akira Hatanakad608bac2012-02-17 02:20:26 +000074 // Promote i8/i16 arguments to i32.
75 CCIfType<[i8, i16], CCPromoteToType<i32>>,
Akira Hatanakad6af2c62011-09-23 19:08:15 +000076
77 // Integer arguments are passed in integer registers.
Akira Hatanakad608bac2012-02-17 02:20:26 +000078 CCIfType<[i32], CCAssignToRegWithShadow<[A0, A1, A2, A3,
79 T0, T1, T2, T3],
80 [F12, F13, F14, F15,
81 F16, F17, F18, F19]>>,
82
Akira Hatanakad6af2c62011-09-23 19:08:15 +000083 CCIfType<[i64], CCAssignToRegWithShadow<[A0_64, A1_64, A2_64, A3_64,
84 T0_64, T1_64, T2_64, T3_64],
85 [D12_64, D13_64, D14_64, D15_64,
86 D16_64, D17_64, D18_64, D19_64]>>,
87
88 // f32 arguments are passed in single precision FP registers.
89 CCIfType<[f32], CCAssignToRegWithShadow<[F12, F13, F14, F15,
90 F16, F17, F18, F19],
91 [A0_64, A1_64, A2_64, A3_64,
92 T0_64, T1_64, T2_64, T3_64]>>,
93
94 // f64 arguments are passed in double precision FP registers.
95 CCIfType<[f64], CCAssignToRegWithShadow<[D12_64, D13_64, D14_64, D15_64,
96 D16_64, D17_64, D18_64, D19_64],
97 [A0_64, A1_64, A2_64, A3_64,
98 T0_64, T1_64, T2_64, T3_64]>>,
99
100 // All stack parameter slots become 64-bit doublewords and are 8-byte aligned.
Akira Hatanakad608bac2012-02-17 02:20:26 +0000101 CCIfType<[i32, f32], CCAssignToStack<4, 8>>,
102 CCIfType<[i64, f64], CCAssignToStack<8, 8>>
Akira Hatanakad6af2c62011-09-23 19:08:15 +0000103]>;
104
Akira Hatanaka0b8bc002011-11-14 19:02:54 +0000105// N32/64 variable arguments.
106// All arguments are passed in integer registers.
107def CC_MipsN_VarArg : CallingConv<[
Akira Hatanakad608bac2012-02-17 02:20:26 +0000108 // Promote i8/i16 arguments to i32.
109 CCIfType<[i8, i16], CCPromoteToType<i32>>,
110
111 CCIfType<[i32, f32], CCAssignToReg<[A0, A1, A2, A3, T0, T1, T2, T3]>>,
Akira Hatanaka0b8bc002011-11-14 19:02:54 +0000112
113 CCIfType<[i64, f64], CCAssignToReg<[A0_64, A1_64, A2_64, A3_64,
114 T0_64, T1_64, T2_64, T3_64]>>,
115
Akira Hatanaka0b8bc002011-11-14 19:02:54 +0000116 // All stack parameter slots become 64-bit doublewords and are 8-byte aligned.
Akira Hatanakad608bac2012-02-17 02:20:26 +0000117 CCIfType<[i32, f32], CCAssignToStack<4, 8>>,
118 CCIfType<[i64, f64], CCAssignToStack<8, 8>>
Akira Hatanaka0b8bc002011-11-14 19:02:54 +0000119]>;
120
Akira Hatanakad6af2c62011-09-23 19:08:15 +0000121def RetCC_MipsN : CallingConv<[
Daniel Sandersb3ca3382014-09-26 10:06:12 +0000122 // f128 needs to be handled similarly to f32 and f64. However, f128 is not
123 // legal and is lowered to i128 which is further lowered to a pair of i64's.
124 // This presents us with a problem for the calling convention since hard-float
125 // still needs to pass them in FPU registers, and soft-float needs to use $v0,
126 // and $a0 instead of the usual $v0, and $v1. We therefore resort to a
127 // pre-analyze (see PreAnalyzeReturnForF128()) step to pass information on
128 // whether the result was originally an f128 into the tablegen-erated code.
129 //
130 // f128 should only occur for the N64 ABI where long double is 128-bit. On
131 // N32, long double is equivalent to double.
132 CCIfType<[i64],
133 CCIf<"static_cast<MipsCCState *>(&State)->WasOriginalArgF128(ValNo)",
134 CCDelegateTo<RetCC_F128>>>,
135
Daniel Sandersae275e32014-09-25 12:15:05 +0000136 // Aggregate returns are positioned at the lowest address in the slot for
137 // both little and big-endian targets. When passing in registers, this
138 // requires that big-endian targets shift the value into the upper bits.
139 CCIfSubtarget<"isLittle()",
Daniel Sanders19f01652014-10-24 13:09:19 +0000140 CCIfType<[i8, i16, i32, i64], CCIfInReg<CCPromoteToType<i64>>>>,
Daniel Sandersae275e32014-09-25 12:15:05 +0000141 CCIfSubtargetNot<"isLittle()",
Daniel Sanders19f01652014-10-24 13:09:19 +0000142 CCIfType<[i8, i16, i32, i64], CCIfInReg<CCPromoteToUpperBitsInType<i64>>>>,
Daniel Sandersae275e32014-09-25 12:15:05 +0000143
Akira Hatanakad6af2c62011-09-23 19:08:15 +0000144 // i32 are returned in registers V0, V1
145 CCIfType<[i32], CCAssignToReg<[V0, V1]>>,
146
147 // i64 are returned in registers V0_64, V1_64
148 CCIfType<[i64], CCAssignToReg<[V0_64, V1_64]>>,
149
150 // f32 are returned in registers F0, F2
151 CCIfType<[f32], CCAssignToReg<[F0, F2]>>,
152
153 // f64 are returned in registers D0, D2
154 CCIfType<[f64], CCAssignToReg<[D0_64, D2_64]>>
155]>;
156
157//===----------------------------------------------------------------------===//
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +0000158// Mips EABI Calling Convention
Akira Hatanakae2489122011-04-15 21:51:11 +0000159//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes3b7b3012009-03-19 02:12:28 +0000160
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +0000161def CC_MipsEABI : CallingConv<[
162 // Promote i8/i16 arguments to i32.
163 CCIfType<[i8, i16], CCPromoteToType<i32>>,
164
165 // Integer arguments are passed in integer registers.
166 CCIfType<[i32], CCAssignToReg<[A0, A1, A2, A3, T0, T1, T2, T3]>>,
167
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000168 // Single fp arguments are passed in pairs within 32-bit mode
169 CCIfType<[f32], CCIfSubtarget<"isSingleFloat()",
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +0000170 CCAssignToReg<[F12, F13, F14, F15, F16, F17, F18, F19]>>>,
171
Daniel Sanders24b65722014-09-10 12:02:27 +0000172 CCIfType<[f32], CCIfSubtargetNot<"isSingleFloat()",
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +0000173 CCAssignToReg<[F12, F14, F16, F18]>>>,
174
Duncan Sands56ca6292011-04-25 06:21:43 +0000175 // The first 4 double fp arguments are passed in single fp registers.
Daniel Sanders24b65722014-09-10 12:02:27 +0000176 CCIfType<[f64], CCIfSubtargetNot<"isSingleFloat()",
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +0000177 CCAssignToReg<[D6, D7, D8, D9]>>>,
178
179 // Integer values get stored in stack slots that are 4 bytes in
180 // size and 4-byte aligned.
181 CCIfType<[i32, f32], CCAssignToStack<4, 4>>,
182
183 // Integer values get stored in stack slots that are 8 bytes in
184 // size and 8-byte aligned.
Daniel Sanders24b65722014-09-10 12:02:27 +0000185 CCIfType<[f64], CCIfSubtargetNot<"isSingleFloat()", CCAssignToStack<8, 8>>>
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +0000186]>;
187
188def RetCC_MipsEABI : CallingConv<[
189 // i32 are returned in registers V0, V1
190 CCIfType<[i32], CCAssignToReg<[V0, V1]>>,
191
192 // f32 are returned in registers F0, F1
193 CCIfType<[f32], CCAssignToReg<[F0, F1]>>,
194
195 // f64 are returned in register D0
Daniel Sanders24b65722014-09-10 12:02:27 +0000196 CCIfType<[f64], CCIfSubtargetNot<"isSingleFloat()", CCAssignToReg<[D0]>>>
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +0000197]>;
198
Akira Hatanakae2489122011-04-15 21:51:11 +0000199//===----------------------------------------------------------------------===//
Akira Hatanakaf0273602012-06-13 18:06:00 +0000200// Mips FastCC Calling Convention
201//===----------------------------------------------------------------------===//
202def CC_MipsO32_FastCC : CallingConv<[
203 // f64 arguments are passed in double-precision floating pointer registers.
Daniel Sanders24b65722014-09-10 12:02:27 +0000204 CCIfType<[f64], CCIfSubtargetNot<"isFP64bit()",
205 CCAssignToReg<[D0, D1, D2, D3, D4, D5, D6,
206 D7, D8, D9]>>>,
Sasa Stankovic86ebfe22014-08-22 09:23:22 +0000207 CCIfType<[f64], CCIfSubtarget<"isFP64bit()", CCIfSubtarget<"useOddSPReg()",
Akira Hatanakabfb66242013-08-20 23:38:40 +0000208 CCAssignToReg<[D0_64, D1_64, D2_64, D3_64,
209 D4_64, D5_64, D6_64, D7_64,
210 D8_64, D9_64, D10_64, D11_64,
211 D12_64, D13_64, D14_64, D15_64,
212 D16_64, D17_64, D18_64,
Sasa Stankovic86ebfe22014-08-22 09:23:22 +0000213 D19_64]>>>>,
214 CCIfType<[f64], CCIfSubtarget<"isFP64bit()", CCIfSubtarget<"noOddSPReg()",
215 CCAssignToReg<[D0_64, D2_64, D4_64, D6_64,
216 D8_64, D10_64, D12_64, D14_64,
217 D16_64, D18_64]>>>>,
Akira Hatanakaf0273602012-06-13 18:06:00 +0000218
219 // Stack parameter slots for f64 are 64-bit doublewords and 8-byte aligned.
220 CCIfType<[f64], CCAssignToStack<8, 8>>
221]>;
222
223def CC_MipsN_FastCC : CallingConv<[
224 // Integer arguments are passed in integer registers.
225 CCIfType<[i64], CCAssignToReg<[A0_64, A1_64, A2_64, A3_64, T0_64, T1_64,
226 T2_64, T3_64, T4_64, T5_64, T6_64, T7_64,
227 T8_64, V1_64]>>,
228
229 // f64 arguments are passed in double-precision floating pointer registers.
230 CCIfType<[f64], CCAssignToReg<[D0_64, D1_64, D2_64, D3_64, D4_64, D5_64,
231 D6_64, D7_64, D8_64, D9_64, D10_64, D11_64,
232 D12_64, D13_64, D14_64, D15_64, D16_64, D17_64,
233 D18_64, D19_64]>>,
234
235 // Stack parameter slots for i64 and f64 are 64-bit doublewords and
236 // 8-byte aligned.
237 CCIfType<[i64, f64], CCAssignToStack<8, 8>>
238]>;
239
240def CC_Mips_FastCC : CallingConv<[
241 // Handles byval parameters.
242 CCIfByVal<CCPassByVal<4, 4>>,
243
244 // Promote i8/i16 arguments to i32.
245 CCIfType<[i8, i16], CCPromoteToType<i32>>,
246
247 // Integer arguments are passed in integer registers. All scratch registers,
248 // except for AT, V0 and T9, are available to be used as argument registers.
Daniel Sanders24b65722014-09-10 12:02:27 +0000249 CCIfType<[i32], CCIfSubtargetNot<"isTargetNaCl()",
Sasa Stankovic4c80bda2014-02-07 17:16:40 +0000250 CCAssignToReg<[A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, V1]>>>,
251
252 // In NaCl, T6, T7 and T8 are reserved and not available as argument
253 // registers for fastcc. T6 contains the mask for sandboxing control flow
254 // (indirect jumps and calls). T7 contains the mask for sandboxing memory
255 // accesses (loads and stores). T8 contains the thread pointer.
256 CCIfType<[i32], CCIfSubtarget<"isTargetNaCl()",
257 CCAssignToReg<[A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, V1]>>>,
Akira Hatanakaf0273602012-06-13 18:06:00 +0000258
259 // f32 arguments are passed in single-precision floating pointer registers.
Sasa Stankovicf4a9e3b2014-07-29 14:39:24 +0000260 CCIfType<[f32], CCIfSubtarget<"useOddSPReg()",
261 CCAssignToReg<[F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13,
262 F14, F15, F16, F17, F18, F19]>>>,
263
264 // Don't use odd numbered single-precision registers for -mno-odd-spreg.
265 CCIfType<[f32], CCIfSubtarget<"noOddSPReg()",
266 CCAssignToReg<[F0, F2, F4, F6, F8, F10, F12, F14, F16, F18]>>>,
Akira Hatanakaf0273602012-06-13 18:06:00 +0000267
268 // Stack parameter slots for i32 and f32 are 32-bit words and 4-byte aligned.
269 CCIfType<[i32, f32], CCAssignToStack<4, 4>>,
270
271 CCIfSubtarget<"isABI_EABI()", CCDelegateTo<CC_MipsEABI>>,
272 CCIfSubtarget<"isABI_O32()", CCDelegateTo<CC_MipsO32_FastCC>>,
273 CCDelegateTo<CC_MipsN_FastCC>
274]>;
275
Reed Kotler783c7942013-05-10 22:25:39 +0000276//==
277
278def CC_Mips16RetHelper : CallingConv<[
279 // Integer arguments are passed in integer registers.
280 CCIfType<[i32], CCAssignToReg<[V0, V1, A0, A1]>>
281]>;
282
Akira Hatanakaf0273602012-06-13 18:06:00 +0000283//===----------------------------------------------------------------------===//
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +0000284// Mips Calling Convention Dispatch
Akira Hatanakae2489122011-04-15 21:51:11 +0000285//===----------------------------------------------------------------------===//
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +0000286
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +0000287def RetCC_Mips : CallingConv<[
288 CCIfSubtarget<"isABI_EABI()", CCDelegateTo<RetCC_MipsEABI>>,
Akira Hatanakad6af2c62011-09-23 19:08:15 +0000289 CCIfSubtarget<"isABI_N32()", CCDelegateTo<RetCC_MipsN>>,
290 CCIfSubtarget<"isABI_N64()", CCDelegateTo<RetCC_MipsN>>,
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +0000291 CCDelegateTo<RetCC_MipsO32>
292]>;
Akira Hatanaka5350c242012-03-01 22:27:29 +0000293
294//===----------------------------------------------------------------------===//
295// Callee-saved register lists.
296//===----------------------------------------------------------------------===//
297
298def CSR_SingleFloatOnly : CalleeSavedRegs<(add (sequence "F%u", 31, 20), RA, FP,
299 (sequence "S%u", 7, 0))>;
300
Zoran Jovanovic255d00d2014-07-10 15:36:12 +0000301def CSR_O32_FPXX : CalleeSavedRegs<(add (sequence "D%u", 15, 10), RA, FP,
302 (sequence "S%u", 7, 0))> {
303 let OtherPreserved = (add (decimate (sequence "F%u", 30, 20), 2));
304}
305
Akira Hatanaka5350c242012-03-01 22:27:29 +0000306def CSR_O32 : CalleeSavedRegs<(add (sequence "D%u", 15, 10), RA, FP,
307 (sequence "S%u", 7, 0))>;
308
Zoran Jovanovicf34b4542014-07-10 22:23:30 +0000309def CSR_O32_FP64 :
310 CalleeSavedRegs<(add (decimate (sequence "D%u_64", 30, 20), 2), RA, FP,
311 (sequence "S%u", 7, 0))>;
Akira Hatanakabfb66242013-08-20 23:38:40 +0000312
Daniel Sanders11c0c062014-04-16 10:23:37 +0000313def CSR_N32 : CalleeSavedRegs<(add D20_64, D22_64, D24_64, D26_64, D28_64,
314 D30_64, RA_64, FP_64, GP_64,
Akira Hatanaka5350c242012-03-01 22:27:29 +0000315 (sequence "S%u_64", 7, 0))>;
316
317def CSR_N64 : CalleeSavedRegs<(add (sequence "D%u_64", 31, 24), RA_64, FP_64,
318 GP_64, (sequence "S%u_64", 7, 0))>;
Reed Kotler783c7942013-05-10 22:25:39 +0000319
Jack Carter59817112013-05-16 20:08:49 +0000320def CSR_Mips16RetHelper :
Reed Kotler5c29d632013-12-15 20:49:30 +0000321 CalleeSavedRegs<(add V0, V1, FP,
322 (sequence "A%u", 3, 0), (sequence "S%u", 7, 0),
323 (sequence "D%u", 15, 10))>;