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("static_cast<const SystemZSubtarget&>"
16 "(State.getMachineFunction().getSubtarget()).", 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 was widened from a short vector type.
24 class CCIfShortVector<CCAction A>
25 : CCIf<"static_cast<SystemZCCState *>(&State)->IsShortVector(ValNo)", A>;
28 //===----------------------------------------------------------------------===//
29 // z/Linux return value calling convention
30 //===----------------------------------------------------------------------===//
31 def RetCC_SystemZ : CallingConv<[
32 // Promote i32 to i64 if it has an explicit extension type.
33 CCIfType<[i32], CCIfExtend<CCPromoteToType<i64>>>,
35 // A SwiftError is returned in R9.
36 CCIfSwiftError<CCIfType<[i64], CCAssignToReg<[R9D]>>>,
38 // ABI-compliant code returns 64-bit integers in R2. Make the other
39 // call-clobbered argument registers available for code that doesn't
40 // care about the ABI. (R6 is an argument register too, but is
41 // call-saved and therefore not suitable for return values.)
42 CCIfType<[i32], CCAssignToReg<[R2L, R3L, R4L, R5L]>>,
43 CCIfType<[i64], CCAssignToReg<[R2D, R3D, R4D, R5D]>>,
45 // ABI-complaint code returns float and double in F0. Make the
46 // other floating-point argument registers available for code that
47 // doesn't care about the ABI. All floating-point argument registers
48 // are call-clobbered, so we can use all of them here.
49 CCIfType<[f32], CCAssignToReg<[F0S, F2S, F4S, F6S]>>,
50 CCIfType<[f64], CCAssignToReg<[F0D, F2D, F4D, F6D]>>,
52 // Similarly for vectors, with V24 being the ABI-compliant choice.
53 // Sub-128 vectors are returned in the same way, but they're widened
54 // to one of these types during type legalization.
55 CCIfSubtarget<"hasVector()",
56 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
57 CCAssignToReg<[V24, V26, V28, V30, V25, V27, V29, V31]>>>
60 //===----------------------------------------------------------------------===//
61 // z/Linux argument calling conventions for GHC
62 //===----------------------------------------------------------------------===//
63 def CC_SystemZ_GHC : CallingConv<[
64 // Pass in STG registers: Base, Sp, Hp, R1, R2, R3, R4, R5, R6, R7, R8, SpLim
65 CCIfType<[i64], CCAssignToReg<[R7D, R8D, R10D, R11D, R12D, R13D,
66 R6D, R2D, R3D, R4D, R5D, R9D]>>,
68 // Pass in STG registers: F1, ..., F6
69 CCIfType<[f32], CCAssignToReg<[F8S, F9S, F10S, F11S, F0S, F1S]>>,
71 // Pass in STG registers: D1, ..., D6
72 CCIfType<[f64], CCAssignToReg<[F12D, F13D, F14D, F15D, F2D, F3D]>>,
74 // Pass in STG registers: XMM1, ..., XMM6
75 CCIfSubtarget<"hasVector()",
76 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
77 CCIfFixed<CCAssignToReg<[V16, V17, V18, V19, V20, V21]>>>>,
80 CCCustom<"CC_SystemZ_GHC_Error">
83 //===----------------------------------------------------------------------===//
84 // z/Linux argument calling conventions
85 //===----------------------------------------------------------------------===//
86 def CC_SystemZ : CallingConv<[
87 CCIfCC<"CallingConv::GHC", CCDelegateTo<CC_SystemZ_GHC>>,
89 // Promote i32 to i64 if it has an explicit extension type.
90 // The convention is that true integer arguments that are smaller
91 // than 64 bits should be marked as extended, but structures that
92 // are smaller than 64 bits shouldn't.
93 CCIfType<[i32], CCIfExtend<CCPromoteToType<i64>>>,
95 // A SwiftSelf is passed in callee-saved R10.
96 CCIfSwiftSelf<CCIfType<[i64], CCAssignToReg<[R10D]>>>,
98 // A SwiftError is passed in callee-saved R9.
99 CCIfSwiftError<CCIfType<[i64], CCAssignToReg<[R9D]>>>,
101 // Force long double values to the stack and pass i64 pointers to them.
102 CCIfType<[f128], CCPassIndirect<i64>>,
103 // Same for i128 values. These are already split into two i64 here,
104 // so we have to use a custom handler.
105 CCIfType<[i64], CCCustom<"CC_SystemZ_I128Indirect">>,
107 // The first 5 integer arguments are passed in R2-R6. Note that R6
109 CCIfType<[i32], CCAssignToReg<[R2L, R3L, R4L, R5L, R6L]>>,
110 CCIfType<[i64], CCAssignToReg<[R2D, R3D, R4D, R5D, R6D]>>,
112 // The first 4 float and double arguments are passed in even registers F0-F6.
113 CCIfType<[f32], CCAssignToReg<[F0S, F2S, F4S, F6S]>>,
114 CCIfType<[f64], CCAssignToReg<[F0D, F2D, F4D, F6D]>>,
116 // The first 8 named vector arguments are passed in V24-V31. Sub-128 vectors
117 // are passed in the same way, but they're widened to one of these types
118 // during type legalization.
119 CCIfSubtarget<"hasVector()",
120 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
121 CCIfFixed<CCAssignToReg<[V24, V26, V28, V30,
122 V25, V27, V29, V31]>>>>,
124 // However, sub-128 vectors which need to go on the stack occupy just a
125 // single 8-byte-aligned 8-byte stack slot. Pass as i64.
126 CCIfSubtarget<"hasVector()",
127 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
128 CCIfShortVector<CCBitConvertToType<i64>>>>,
130 // Other vector arguments are passed in 8-byte-aligned 16-byte stack slots.
131 CCIfSubtarget<"hasVector()",
132 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
133 CCAssignToStack<16, 8>>>,
135 // Other arguments are passed in 8-byte-aligned 8-byte stack slots.
136 CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>
139 //===----------------------------------------------------------------------===//
140 // z/Linux callee-saved registers
141 //===----------------------------------------------------------------------===//
142 def CSR_SystemZ : CalleeSavedRegs<(add (sequence "R%dD", 6, 15),
143 (sequence "F%dD", 8, 15))>;
145 // R9 is used to return SwiftError; remove it from CSR.
146 def CSR_SystemZ_SwiftError : CalleeSavedRegs<(sub CSR_SystemZ, R9D)>;
148 // "All registers" as used by the AnyReg calling convention.
149 // Note that registers 0 and 1 are still defined as intra-call scratch
150 // registers that may be clobbered e.g. by PLT stubs.
151 def CSR_SystemZ_AllRegs : CalleeSavedRegs<(add (sequence "R%dD", 2, 15),
152 (sequence "F%dD", 0, 15))>;
153 def CSR_SystemZ_AllRegs_Vector : CalleeSavedRegs<(add (sequence "R%dD", 2, 15),
154 (sequence "V%d", 0, 31))>;
156 def CSR_SystemZ_NoRegs : CalleeSavedRegs<(add)>;