1 //=- SystemZCallingConv.td - Calling conventions for SystemZ -*- tablegen -*-=//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
8 // This describes the calling conventions for the SystemZ ABI.
9 //===----------------------------------------------------------------------===//
11 class CCIfExtend<CCAction A>
12 : CCIf<"ArgFlags.isSExt() || ArgFlags.isZExt()", A>;
14 class CCIfSubtarget<string F, CCAction A>
15 : CCIf<!strconcat("State.getMachineFunction()."
16 "getSubtarget<SystemZSubtarget>().", F),
19 // Match if this specific argument is a fixed (i.e. named) argument.
20 class CCIfFixed<CCAction A>
21 : CCIf<"static_cast<SystemZCCState *>(&State)->IsFixed(ValNo)", A>;
23 // Match if this specific argument is not a fixed (i.e. vararg) argument.
24 class CCIfNotFixed<CCAction A>
25 : CCIf<"!(static_cast<SystemZCCState *>(&State)->IsFixed(ValNo))", A>;
27 // Match if this specific argument was widened from a short vector type.
28 class CCIfShortVector<CCAction A>
29 : CCIf<"static_cast<SystemZCCState *>(&State)->IsShortVector(ValNo)", A>;
32 //===----------------------------------------------------------------------===//
33 // z/Linux return value calling convention
34 //===----------------------------------------------------------------------===//
35 def RetCC_SystemZ_ELF : CallingConv<[
36 // Promote i32 to i64 if it has an explicit extension type.
37 CCIfType<[i32], CCIfExtend<CCPromoteToType<i64>>>,
39 // A SwiftError is returned in R9.
40 CCIfSwiftError<CCIfType<[i64], CCAssignToReg<[R9D]>>>,
42 // ABI-compliant code returns 64-bit integers in R2. Make the other
43 // call-clobbered argument registers available for code that doesn't
44 // care about the ABI. (R6 is an argument register too, but is
45 // call-saved and therefore not suitable for return values.)
46 CCIfType<[i32], CCAssignToReg<[R2L, R3L, R4L, R5L]>>,
47 CCIfType<[i64], CCAssignToReg<[R2D, R3D, R4D, R5D]>>,
49 // ABI-complaint code returns float and double in F0. Make the
50 // other floating-point argument registers available for code that
51 // doesn't care about the ABI. All floating-point argument registers
52 // are call-clobbered, so we can use all of them here.
53 CCIfType<[f32], CCAssignToReg<[F0S, F2S, F4S, F6S]>>,
54 CCIfType<[f64], CCAssignToReg<[F0D, F2D, F4D, F6D]>>,
56 // Similarly for vectors, with V24 being the ABI-compliant choice.
57 // Sub-128 vectors are returned in the same way, but they're widened
58 // to one of these types during type legalization.
59 CCIfSubtarget<"hasVector()",
60 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
61 CCAssignToReg<[V24, V26, V28, V30, V25, V27, V29, V31]>>>
64 //===----------------------------------------------------------------------===//
65 // z/Linux argument calling conventions for GHC
66 //===----------------------------------------------------------------------===//
67 def CC_SystemZ_GHC : CallingConv<[
68 // Pass in STG registers: Base, Sp, Hp, R1, R2, R3, R4, R5, R6, R7, R8, SpLim
69 CCIfType<[i64], CCAssignToReg<[R7D, R8D, R10D, R11D, R12D, R13D,
70 R6D, R2D, R3D, R4D, R5D, R9D]>>,
72 // Pass in STG registers: F1, ..., F6
73 CCIfType<[f32], CCAssignToReg<[F8S, F9S, F10S, F11S, F0S, F1S]>>,
75 // Pass in STG registers: D1, ..., D6
76 CCIfType<[f64], CCAssignToReg<[F12D, F13D, F14D, F15D, F2D, F3D]>>,
78 // Pass in STG registers: XMM1, ..., XMM6
79 CCIfSubtarget<"hasVector()",
80 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
81 CCIfFixed<CCAssignToReg<[V16, V17, V18, V19, V20, V21]>>>>,
84 CCCustom<"CC_SystemZ_GHC_Error">
87 //===----------------------------------------------------------------------===//
88 // z/Linux argument calling conventions
89 //===----------------------------------------------------------------------===//
90 def CC_SystemZ_ELF : CallingConv<[
91 CCIfCC<"CallingConv::GHC", CCDelegateTo<CC_SystemZ_GHC>>,
93 // Promote i32 to i64 if it has an explicit extension type.
94 // The convention is that true integer arguments that are smaller
95 // than 64 bits should be marked as extended, but structures that
96 // are smaller than 64 bits shouldn't.
97 CCIfType<[i32], CCIfExtend<CCPromoteToType<i64>>>,
99 // A SwiftSelf is passed in callee-saved R10.
100 CCIfSwiftSelf<CCIfType<[i64], CCAssignToReg<[R10D]>>>,
102 // A SwiftError is passed in callee-saved R9.
103 CCIfSwiftError<CCIfType<[i64], CCAssignToReg<[R9D]>>>,
105 // Force i128 (if the type is legal) and long double values to the stack
106 // and pass i64 pointers to them.
107 CCIfType<[i128, f128], CCPassIndirect<i64>>,
108 // If i128 is not legal, such values are already split into two i64 here,
109 // so we have to use a custom handler.
110 CCIfType<[i64], CCCustom<"CC_SystemZ_I128Indirect">>,
112 // The first 5 integer arguments are passed in R2-R6. Note that R6
114 CCIfType<[i32], CCAssignToReg<[R2L, R3L, R4L, R5L, R6L]>>,
115 CCIfType<[i64], CCAssignToReg<[R2D, R3D, R4D, R5D, R6D]>>,
117 // The first 4 float and double arguments are passed in even registers F0-F6.
118 CCIfType<[f32], CCAssignToReg<[F0S, F2S, F4S, F6S]>>,
119 CCIfType<[f64], CCAssignToReg<[F0D, F2D, F4D, F6D]>>,
121 // The first 8 named vector arguments are passed in V24-V31. Sub-128 vectors
122 // are passed in the same way, but they're widened to one of these types
123 // during type legalization.
124 CCIfSubtarget<"hasVector()",
125 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
126 CCIfFixed<CCAssignToReg<[V24, V26, V28, V30,
127 V25, V27, V29, V31]>>>>,
129 // However, sub-128 vectors which need to go on the stack occupy just a
130 // single 8-byte-aligned 8-byte stack slot. Pass as i64.
131 CCIfSubtarget<"hasVector()",
132 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
133 CCIfShortVector<CCBitConvertToType<i64>>>>,
135 // Other vector arguments are passed in 8-byte-aligned 16-byte stack slots.
136 CCIfSubtarget<"hasVector()",
137 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
138 CCAssignToStack<16, 8>>>,
140 // Other arguments are passed in 8-byte-aligned 8-byte stack slots.
141 CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>
144 //===----------------------------------------------------------------------===//
145 // z/Linux callee-saved registers
146 //===----------------------------------------------------------------------===//
147 def CSR_SystemZ_ELF : CalleeSavedRegs<(add (sequence "R%dD", 6, 15),
148 (sequence "F%dD", 8, 15))>;
150 // R9 is used to return SwiftError; remove it from CSR.
151 def CSR_SystemZ_SwiftError : CalleeSavedRegs<(sub CSR_SystemZ_ELF, R9D)>;
153 // "All registers" as used by the AnyReg calling convention.
154 // Note that registers 0 and 1 are still defined as intra-call scratch
155 // registers that may be clobbered e.g. by PLT stubs.
156 def CSR_SystemZ_AllRegs : CalleeSavedRegs<(add (sequence "R%dD", 2, 15),
157 (sequence "F%dD", 0, 15))>;
158 def CSR_SystemZ_AllRegs_Vector : CalleeSavedRegs<(add (sequence "R%dD", 2, 15),
159 (sequence "V%d", 0, 31))>;
161 def CSR_SystemZ_NoRegs : CalleeSavedRegs<(add)>;
163 //===----------------------------------------------------------------------===//
164 // z/OS XPLINK64 callee-saved registers
165 //===----------------------------------------------------------------------===//
166 def CSR_SystemZ_XPLINK64 : CalleeSavedRegs<(add (sequence "R%dD", 8, 15),
167 (sequence "F%dD", 15, 8))>;
169 def CSR_SystemZ_XPLINK64_Vector : CalleeSavedRegs<(add CSR_SystemZ_XPLINK64,
170 (sequence "V%d", 23, 16))>;
172 //===----------------------------------------------------------------------===//
173 // z/OS XPLINK64 return value calling convention
174 //===----------------------------------------------------------------------===//
175 def RetCC_SystemZ_XPLINK64 : CallingConv<[
176 // XPLINK64 ABI compliant code widens integral types smaller than i64
178 CCIfType<[i32], CCPromoteToType<i64>>,
180 // Structs of size 1-24 bytes are returned in R1D, R2D, and R3D.
181 CCIfType<[i64], CCIfInReg<CCAssignToReg<[R1D, R2D, R3D]>>>,
182 // An i64 is returned in R3D. R2D and R1D provided for ABI non-compliant
184 CCIfType<[i64], CCAssignToReg<[R3D, R2D, R1D]>>,
186 // ABI compliant code returns floating point values in FPR0, FPR2, FPR4
187 // and FPR6, using as many registers as required.
188 // All floating point return-value registers are call-clobbered.
189 CCIfType<[f32], CCAssignToReg<[F0S, F2S, F4S, F6S]>>,
190 CCIfType<[f64], CCAssignToReg<[F0D, F2D, F4D, F6D]>>,
192 // ABI compliant code returns f128 in F0D and F2D, hence F0Q.
193 // F4D and F6D, hence F4Q are used for complex long double types.
194 CCIfType<[f128], CCAssignToReg<[F0Q,F4Q]>>,
196 // ABI compliant code returns vectors in VR24 but other registers
197 // are provided for code that does not care about the ABI.
198 CCIfSubtarget<"hasVector()",
199 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
200 CCAssignToReg<[V24, V25, V26, V27, V28, V29, V30, V31]>>>
203 //===----------------------------------------------------------------------===//
204 // z/OS XPLINK64 argument calling conventions
205 //===----------------------------------------------------------------------===//
206 // XPLink uses a logical argument list consisting of contiguous register-size
207 // words (8 bytes in 64-Bit mode) where some arguments are passed in registers
208 // and some in storage.
209 // Even though 3 GPRs, 4 FPRs, and 8 VRs may be used,
210 // space must be reserved for all the args on stack.
211 // The first three register-sized words of the parameter area are passed in
212 // GPRs 1-3. FP values and vector-type arguments are instead passed in FPRs
213 // and VRs respectively, but if a FP value or vector argument occupies one of
214 // the first three register-sized words of the parameter area, the corresponding
215 // GPR's value is not used to pass arguments.
217 // The XPLINK64 Calling Convention is fully specified in Chapter 22 of the z/OS
218 // Language Environment Vendor Interfaces. Appendix B of the same document contains
221 def CC_SystemZ_XPLINK64 : CallingConv<[
222 // XPLINK64 ABI compliant code widens integral types smaller than i64
223 // to i64 before placing the parameters either on the stack or in registers.
224 CCIfType<[i32], CCIfExtend<CCPromoteToType<i64>>>,
225 // Promote f32 to f64 and bitcast to i64, if it needs to be passed in GPRs.
226 // Although we assign the f32 vararg to be bitcast, it will first be promoted
227 // to an f64 within convertValVTToLocVT().
228 CCIfType<[f32, f64], CCIfNotFixed<CCBitConvertToType<i64>>>,
229 // Pointers are always passed in full 64-bit registers.
230 CCIfPtr<CCCustom<"CC_XPLINK64_Pointer">>,
231 // long double, can only be passed in GPR2 and GPR3, if available,
233 CCIfType<[f128], CCIfNotFixed<CCCustom<"CC_XPLINK64_Allocate128BitVararg">>>,
234 // Non fixed vector arguments are treated in the same way as long
236 CCIfSubtarget<"hasVector()",
237 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
238 CCIfNotFixed<CCCustom<"CC_XPLINK64_Allocate128BitVararg">>>>,
240 // A SwiftSelf is passed in callee-saved R10.
241 CCIfSwiftSelf<CCIfType<[i64], CCAssignToReg<[R10D]>>>,
243 // A SwiftError is passed in R0.
244 CCIfSwiftError<CCIfType<[i64], CCAssignToReg<[R0D]>>>,
246 // Force i128 values to the stack and pass i64 pointers to them.
247 CCIfType<[i128], CCPassIndirect<i64>>,
248 // If i128 is not legal, such values are already split into two i64 here,
249 // so we have to use a custom handler.
250 CCIfType<[i64], CCCustom<"CC_SystemZ_I128Indirect">>,
251 // The first 3 integer arguments are passed in registers R1D-R3D.
252 // The rest will be passed in the user area. The address offset of the user
253 // area can be found in register R4D.
254 CCIfType<[i64], CCAssignToRegAndStack<[R1D, R2D, R3D], 8, 8>>,
256 // The first 8 named vector arguments are passed in V24-V31. Sub-128 vectors
257 // are passed in the same way, but they're widened to one of these types
258 // during type legalization.
259 CCIfSubtarget<"hasVector()",
260 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
261 CCIfFixed<CCCustom<"CC_XPLINK64_Shadow_Reg">>>>,
262 CCIfSubtarget<"hasVector()",
263 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
264 CCIfFixed<CCAssignToRegAndStack<[V24, V25, V26, V27,
265 V28, V29, V30, V31], 16, 8>>>>,
267 // The first 4 named float and double arguments are passed in registers
268 // FPR0-FPR6. The rest will be passed in the user area.
269 CCIfType<[f32, f64], CCIfFixed<CCCustom<"CC_XPLINK64_Shadow_Reg">>>,
270 CCIfType<[f32], CCIfFixed<CCAssignToRegAndStack<[F0S, F2S, F4S, F6S], 4, 8>>>,
271 CCIfType<[f64], CCIfFixed<CCAssignToRegAndStack<[F0D, F2D, F4D, F6D], 8, 8>>>,
273 // The first 2 long double arguments are passed in register FPR0/FPR2
274 // and FPR4/FPR6. The rest will be passed in the user area.
275 CCIfType<[f128], CCIfFixed<CCCustom<"CC_XPLINK64_Shadow_Reg">>>,
276 CCIfType<[f128], CCIfFixed<CCAssignToRegAndStack<[F0Q, F4Q], 16, 8>>>,
278 // Other arguments are passed in 8-byte-aligned 8-byte stack slots.
279 CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>,
280 // Other f128 arguments are passed in 8-byte-aligned 16-byte stack slots.
281 CCIfType<[f128], CCAssignToStack<16, 8>>,
282 // Vector arguments are passed in 8-byte-alinged 16-byte stack slots too.
283 CCIfSubtarget<"hasVector()",
284 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
285 CCAssignToStack<16, 8>>>
288 //===----------------------------------------------------------------------===//
289 // s390x return value calling convention
290 //===----------------------------------------------------------------------===//
292 def RetCC_SystemZ : CallingConv<[
294 CCIfSubtarget<"isTargetXPLINK64()", CCDelegateTo<RetCC_SystemZ_XPLINK64>>,
297 CCIfSubtarget<"isTargetELF()", CCDelegateTo<RetCC_SystemZ_ELF>>
301 //===----------------------------------------------------------------------===//
302 // s390x argument calling conventions
303 //===----------------------------------------------------------------------===//
304 def CC_SystemZ : CallingConv<[
306 CCIfSubtarget<"isTargetXPLINK64()", CCDelegateTo<CC_SystemZ_XPLINK64>>,
309 CCIfSubtarget<"isTargetELF()", CCDelegateTo<CC_SystemZ_ELF>>