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
62 //===----------------------------------------------------------------------===//
63 def CC_SystemZ : CallingConv<[
64 // Promote i32 to i64 if it has an explicit extension type.
65 // The convention is that true integer arguments that are smaller
66 // than 64 bits should be marked as extended, but structures that
67 // are smaller than 64 bits shouldn't.
68 CCIfType<[i32], CCIfExtend<CCPromoteToType<i64>>>,
70 // A SwiftSelf is passed in callee-saved R10.
71 CCIfSwiftSelf<CCIfType<[i64], CCAssignToReg<[R10D]>>>,
73 // A SwiftError is passed in callee-saved R9.
74 CCIfSwiftError<CCIfType<[i64], CCAssignToReg<[R9D]>>>,
76 // Force long double values to the stack and pass i64 pointers to them.
77 CCIfType<[f128], CCPassIndirect<i64>>,
78 // Same for i128 values. These are already split into two i64 here,
79 // so we have to use a custom handler.
80 CCIfType<[i64], CCCustom<"CC_SystemZ_I128Indirect">>,
82 // The first 5 integer arguments are passed in R2-R6. Note that R6
84 CCIfType<[i32], CCAssignToReg<[R2L, R3L, R4L, R5L, R6L]>>,
85 CCIfType<[i64], CCAssignToReg<[R2D, R3D, R4D, R5D, R6D]>>,
87 // The first 4 float and double arguments are passed in even registers F0-F6.
88 CCIfType<[f32], CCAssignToReg<[F0S, F2S, F4S, F6S]>>,
89 CCIfType<[f64], CCAssignToReg<[F0D, F2D, F4D, F6D]>>,
91 // The first 8 named vector arguments are passed in V24-V31. Sub-128 vectors
92 // are passed in the same way, but they're widened to one of these types
93 // during type legalization.
94 CCIfSubtarget<"hasVector()",
95 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
96 CCIfFixed<CCAssignToReg<[V24, V26, V28, V30,
97 V25, V27, V29, V31]>>>>,
99 // However, sub-128 vectors which need to go on the stack occupy just a
100 // single 8-byte-aligned 8-byte stack slot. Pass as i64.
101 CCIfSubtarget<"hasVector()",
102 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
103 CCIfShortVector<CCBitConvertToType<i64>>>>,
105 // Other vector arguments are passed in 8-byte-aligned 16-byte stack slots.
106 CCIfSubtarget<"hasVector()",
107 CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
108 CCAssignToStack<16, 8>>>,
110 // Other arguments are passed in 8-byte-aligned 8-byte stack slots.
111 CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>
114 //===----------------------------------------------------------------------===//
115 // z/Linux callee-saved registers
116 //===----------------------------------------------------------------------===//
117 def CSR_SystemZ : CalleeSavedRegs<(add (sequence "R%dD", 6, 15),
118 (sequence "F%dD", 8, 15))>;
120 // R9 is used to return SwiftError; remove it from CSR.
121 def CSR_SystemZ_SwiftError : CalleeSavedRegs<(sub CSR_SystemZ, R9D)>;
123 // "All registers" as used by the AnyReg calling convention.
124 // Note that registers 0 and 1 are still defined as intra-call scratch
125 // registers that may be clobbered e.g. by PLT stubs.
126 def CSR_SystemZ_AllRegs : CalleeSavedRegs<(add (sequence "R%dD", 2, 15),
127 (sequence "F%dD", 0, 15))>;
128 def CSR_SystemZ_AllRegs_Vector : CalleeSavedRegs<(add (sequence "R%dD", 2, 15),
129 (sequence "V%d", 0, 31))>;