1//=- SystemZCallingConv.td - Calling conventions for SystemZ -*- tablegen -*-=// 2// 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 6// 7//===----------------------------------------------------------------------===// 8// This describes the calling conventions for the SystemZ ABI. 9//===----------------------------------------------------------------------===// 10 11class CCIfExtend<CCAction A> 12 : CCIf<"ArgFlags.isSExt() || ArgFlags.isZExt()", A>; 13 14class CCIfSubtarget<string F, CCAction A> 15 : CCIf<!strconcat("static_cast<const SystemZSubtarget&>" 16 "(State.getMachineFunction().getSubtarget()).", F), 17 A>; 18 19// Match if this specific argument is a fixed (i.e. named) argument. 20class CCIfFixed<CCAction A> 21 : CCIf<"static_cast<SystemZCCState *>(&State)->IsFixed(ValNo)", A>; 22 23// Match if this specific argument was widened from a short vector type. 24class CCIfShortVector<CCAction A> 25 : CCIf<"static_cast<SystemZCCState *>(&State)->IsShortVector(ValNo)", A>; 26 27 28//===----------------------------------------------------------------------===// 29// z/Linux return value calling convention 30//===----------------------------------------------------------------------===// 31def RetCC_SystemZ : CallingConv<[ 32 // Promote i32 to i64 if it has an explicit extension type. 33 CCIfType<[i32], CCIfExtend<CCPromoteToType<i64>>>, 34 35 // A SwiftError is returned in R9. 36 CCIfSwiftError<CCIfType<[i64], CCAssignToReg<[R9D]>>>, 37 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]>>, 44 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]>>, 51 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]>>> 58]>; 59 60//===----------------------------------------------------------------------===// 61// z/Linux argument calling conventions 62//===----------------------------------------------------------------------===// 63def 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>>>, 69 70 // A SwiftSelf is passed in callee-saved R10. 71 CCIfSwiftSelf<CCIfType<[i64], CCAssignToReg<[R10D]>>>, 72 73 // A SwiftError is passed in callee-saved R9. 74 CCIfSwiftError<CCIfType<[i64], CCAssignToReg<[R9D]>>>, 75 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">>, 81 82 // The first 5 integer arguments are passed in R2-R6. Note that R6 83 // is call-saved. 84 CCIfType<[i32], CCAssignToReg<[R2L, R3L, R4L, R5L, R6L]>>, 85 CCIfType<[i64], CCAssignToReg<[R2D, R3D, R4D, R5D, R6D]>>, 86 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]>>, 90 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]>>>>, 98 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>>>>, 104 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>>>, 109 110 // Other arguments are passed in 8-byte-aligned 8-byte stack slots. 111 CCIfType<[i32, i64, f32, f64], CCAssignToStack<8, 8>> 112]>; 113 114//===----------------------------------------------------------------------===// 115// z/Linux callee-saved registers 116//===----------------------------------------------------------------------===// 117def CSR_SystemZ : CalleeSavedRegs<(add (sequence "R%dD", 6, 15), 118 (sequence "F%dD", 8, 15))>; 119 120// R9 is used to return SwiftError; remove it from CSR. 121def CSR_SystemZ_SwiftError : CalleeSavedRegs<(sub CSR_SystemZ, R9D)>; 122 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. 126def CSR_SystemZ_AllRegs : CalleeSavedRegs<(add (sequence "R%dD", 2, 15), 127 (sequence "F%dD", 0, 15))>; 128def CSR_SystemZ_AllRegs_Vector : CalleeSavedRegs<(add (sequence "R%dD", 2, 15), 129 (sequence "V%d", 0, 31))>; 130 131