xref: /aosp_15_r20/external/llvm/lib/Target/SystemZ/SystemZCallingConv.td (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker//=- SystemZCallingConv.td - Calling conventions for SystemZ -*- tablegen -*-=//
2*9880d681SAndroid Build Coastguard Worker//
3*9880d681SAndroid Build Coastguard Worker//                     The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker//
5*9880d681SAndroid Build Coastguard Worker// This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker// License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker//
8*9880d681SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker// This describes the calling conventions for the SystemZ ABI.
10*9880d681SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===//
11*9880d681SAndroid Build Coastguard Worker
12*9880d681SAndroid Build Coastguard Workerclass CCIfExtend<CCAction A>
13*9880d681SAndroid Build Coastguard Worker  : CCIf<"ArgFlags.isSExt() || ArgFlags.isZExt()", A>;
14*9880d681SAndroid Build Coastguard Worker
15*9880d681SAndroid Build Coastguard Workerclass CCIfSubtarget<string F, CCAction A>
16*9880d681SAndroid Build Coastguard Worker  : CCIf<!strconcat("static_cast<const SystemZSubtarget&>"
17*9880d681SAndroid Build Coastguard Worker                    "(State.getMachineFunction().getSubtarget()).", F),
18*9880d681SAndroid Build Coastguard Worker         A>;
19*9880d681SAndroid Build Coastguard Worker
20*9880d681SAndroid Build Coastguard Worker// Match if this specific argument is a fixed (i.e. named) argument.
21*9880d681SAndroid Build Coastguard Workerclass CCIfFixed<CCAction A>
22*9880d681SAndroid Build Coastguard Worker    : CCIf<"static_cast<SystemZCCState *>(&State)->IsFixed(ValNo)", A>;
23*9880d681SAndroid Build Coastguard Worker
24*9880d681SAndroid Build Coastguard Worker// Match if this specific argument was widened from a short vector type.
25*9880d681SAndroid Build Coastguard Workerclass CCIfShortVector<CCAction A>
26*9880d681SAndroid Build Coastguard Worker    : CCIf<"static_cast<SystemZCCState *>(&State)->IsShortVector(ValNo)", A>;
27*9880d681SAndroid Build Coastguard Worker
28*9880d681SAndroid Build Coastguard Worker
29*9880d681SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===//
30*9880d681SAndroid Build Coastguard Worker// z/Linux return value calling convention
31*9880d681SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===//
32*9880d681SAndroid Build Coastguard Workerdef RetCC_SystemZ : CallingConv<[
33*9880d681SAndroid Build Coastguard Worker  // Promote i32 to i64 if it has an explicit extension type.
34*9880d681SAndroid Build Coastguard Worker  CCIfType<[i32], CCIfExtend<CCPromoteToType<i64>>>,
35*9880d681SAndroid Build Coastguard Worker
36*9880d681SAndroid Build Coastguard Worker  // A SwiftError is returned in R9.
37*9880d681SAndroid Build Coastguard Worker  CCIfSwiftError<CCIfType<[i64], CCAssignToReg<[R9D]>>>,
38*9880d681SAndroid Build Coastguard Worker
39*9880d681SAndroid Build Coastguard Worker  // ABI-compliant code returns 64-bit integers in R2.  Make the other
40*9880d681SAndroid Build Coastguard Worker  // call-clobbered argument registers available for code that doesn't
41*9880d681SAndroid Build Coastguard Worker  // care about the ABI.  (R6 is an argument register too, but is
42*9880d681SAndroid Build Coastguard Worker  // call-saved and therefore not suitable for return values.)
43*9880d681SAndroid Build Coastguard Worker  CCIfType<[i32], CCAssignToReg<[R2L, R3L, R4L, R5L]>>,
44*9880d681SAndroid Build Coastguard Worker  CCIfType<[i64], CCAssignToReg<[R2D, R3D, R4D, R5D]>>,
45*9880d681SAndroid Build Coastguard Worker
46*9880d681SAndroid Build Coastguard Worker  // ABI-complaint code returns float and double in F0.  Make the
47*9880d681SAndroid Build Coastguard Worker  // other floating-point argument registers available for code that
48*9880d681SAndroid Build Coastguard Worker  // doesn't care about the ABI.  All floating-point argument registers
49*9880d681SAndroid Build Coastguard Worker  // are call-clobbered, so we can use all of them here.
50*9880d681SAndroid Build Coastguard Worker  CCIfType<[f32], CCAssignToReg<[F0S, F2S, F4S, F6S]>>,
51*9880d681SAndroid Build Coastguard Worker  CCIfType<[f64], CCAssignToReg<[F0D, F2D, F4D, F6D]>>,
52*9880d681SAndroid Build Coastguard Worker
53*9880d681SAndroid Build Coastguard Worker  // Similarly for vectors, with V24 being the ABI-compliant choice.
54*9880d681SAndroid Build Coastguard Worker  // Sub-128 vectors are returned in the same way, but they're widened
55*9880d681SAndroid Build Coastguard Worker  // to one of these types during type legalization.
56*9880d681SAndroid Build Coastguard Worker  CCIfSubtarget<"hasVector()",
57*9880d681SAndroid Build Coastguard Worker    CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
58*9880d681SAndroid Build Coastguard Worker             CCAssignToReg<[V24, V26, V28, V30, V25, V27, V29, V31]>>>
59*9880d681SAndroid Build Coastguard Worker]>;
60*9880d681SAndroid Build Coastguard Worker
61*9880d681SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===//
62*9880d681SAndroid Build Coastguard Worker// z/Linux argument calling conventions
63*9880d681SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===//
64*9880d681SAndroid Build Coastguard Workerdef CC_SystemZ : CallingConv<[
65*9880d681SAndroid Build Coastguard Worker  // Promote i32 to i64 if it has an explicit extension type.
66*9880d681SAndroid Build Coastguard Worker  // The convention is that true integer arguments that are smaller
67*9880d681SAndroid Build Coastguard Worker  // than 64 bits should be marked as extended, but structures that
68*9880d681SAndroid Build Coastguard Worker  // are smaller than 64 bits shouldn't.
69*9880d681SAndroid Build Coastguard Worker  CCIfType<[i32], CCIfExtend<CCPromoteToType<i64>>>,
70*9880d681SAndroid Build Coastguard Worker
71*9880d681SAndroid Build Coastguard Worker  // A SwiftSelf is passed in callee-saved R10.
72*9880d681SAndroid Build Coastguard Worker  CCIfSwiftSelf<CCIfType<[i64], CCAssignToReg<[R10D]>>>,
73*9880d681SAndroid Build Coastguard Worker
74*9880d681SAndroid Build Coastguard Worker  // A SwiftError is passed in callee-saved R9.
75*9880d681SAndroid Build Coastguard Worker  CCIfSwiftError<CCIfType<[i64], CCAssignToReg<[R9D]>>>,
76*9880d681SAndroid Build Coastguard Worker
77*9880d681SAndroid Build Coastguard Worker  // Force long double values to the stack and pass i64 pointers to them.
78*9880d681SAndroid Build Coastguard Worker  CCIfType<[f128], CCPassIndirect<i64>>,
79*9880d681SAndroid Build Coastguard Worker  // Same for i128 values.  These are already split into two i64 here,
80*9880d681SAndroid Build Coastguard Worker  // so we have to use a custom handler.
81*9880d681SAndroid Build Coastguard Worker  CCIfType<[i64], CCCustom<"CC_SystemZ_I128Indirect">>,
82*9880d681SAndroid Build Coastguard Worker
83*9880d681SAndroid Build Coastguard Worker  // The first 5 integer arguments are passed in R2-R6.  Note that R6
84*9880d681SAndroid Build Coastguard Worker  // is call-saved.
85*9880d681SAndroid Build Coastguard Worker  CCIfType<[i32], CCAssignToReg<[R2L, R3L, R4L, R5L, R6L]>>,
86*9880d681SAndroid Build Coastguard Worker  CCIfType<[i64], CCAssignToReg<[R2D, R3D, R4D, R5D, R6D]>>,
87*9880d681SAndroid Build Coastguard Worker
88*9880d681SAndroid Build Coastguard Worker  // The first 4 float and double arguments are passed in even registers F0-F6.
89*9880d681SAndroid Build Coastguard Worker  CCIfType<[f32], CCAssignToReg<[F0S, F2S, F4S, F6S]>>,
90*9880d681SAndroid Build Coastguard Worker  CCIfType<[f64], CCAssignToReg<[F0D, F2D, F4D, F6D]>>,
91*9880d681SAndroid Build Coastguard Worker
92*9880d681SAndroid Build Coastguard Worker  // The first 8 named vector arguments are passed in V24-V31.  Sub-128 vectors
93*9880d681SAndroid Build Coastguard Worker  // are passed in the same way, but they're widened to one of these types
94*9880d681SAndroid Build Coastguard Worker  // during type legalization.
95*9880d681SAndroid Build Coastguard Worker  CCIfSubtarget<"hasVector()",
96*9880d681SAndroid Build Coastguard Worker    CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
97*9880d681SAndroid Build Coastguard Worker             CCIfFixed<CCAssignToReg<[V24, V26, V28, V30,
98*9880d681SAndroid Build Coastguard Worker                                      V25, V27, V29, V31]>>>>,
99*9880d681SAndroid Build Coastguard Worker
100*9880d681SAndroid Build Coastguard Worker  // However, sub-128 vectors which need to go on the stack occupy just a
101*9880d681SAndroid Build Coastguard Worker  // single 8-byte-aligned 8-byte stack slot.  Pass as i64.
102*9880d681SAndroid Build Coastguard Worker  CCIfSubtarget<"hasVector()",
103*9880d681SAndroid Build Coastguard Worker    CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
104*9880d681SAndroid Build Coastguard Worker             CCIfShortVector<CCBitConvertToType<i64>>>>,
105*9880d681SAndroid Build Coastguard Worker
106*9880d681SAndroid Build Coastguard Worker  // Other vector arguments are passed in 8-byte-aligned 16-byte stack slots.
107*9880d681SAndroid Build Coastguard Worker  CCIfSubtarget<"hasVector()",
108*9880d681SAndroid Build Coastguard Worker    CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
109*9880d681SAndroid Build Coastguard Worker             CCAssignToStack<16, 8>>>,
110*9880d681SAndroid Build Coastguard Worker
111*9880d681SAndroid Build Coastguard Worker  // Other arguments are passed in 8-byte-aligned 8-byte stack slots.
112*9880d681SAndroid Build Coastguard Worker  CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 8>>
113*9880d681SAndroid Build Coastguard Worker]>;
114*9880d681SAndroid Build Coastguard Worker
115*9880d681SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===//
116*9880d681SAndroid Build Coastguard Worker// z/Linux callee-saved registers
117*9880d681SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===//
118*9880d681SAndroid Build Coastguard Workerdef CSR_SystemZ : CalleeSavedRegs<(add (sequence "R%dD", 6, 15),
119*9880d681SAndroid Build Coastguard Worker                                       (sequence "F%dD", 8, 15))>;
120*9880d681SAndroid Build Coastguard Worker
121*9880d681SAndroid Build Coastguard Worker// R9 is used to return SwiftError; remove it from CSR.
122*9880d681SAndroid Build Coastguard Workerdef CSR_SystemZ_SwiftError : CalleeSavedRegs<(sub CSR_SystemZ, R9D)>;
123