1//===- TargetCallingConv.td - Target Calling Conventions ---*- 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// 9// This file defines the target-independent interfaces with which targets 10// describe their calling conventions. 11// 12//===----------------------------------------------------------------------===// 13 14class CCAction; 15class CallingConv; 16 17/// CCCustom - Calls a custom arg handling function. 18class CCCustom<string fn> : CCAction { 19 string FuncName = fn; 20} 21 22/// CCPredicateAction - Instances of this class check some predicate, then 23/// delegate to another action if the predicate is true. 24class CCPredicateAction<CCAction A> : CCAction { 25 CCAction SubAction = A; 26} 27 28/// CCIfType - If the current argument is one of the specified types, apply 29/// Action A. 30class CCIfType<list<ValueType> vts, CCAction A> : CCPredicateAction<A> { 31 list<ValueType> VTs = vts; 32} 33 34/// CCIf - If the predicate matches, apply A. 35class CCIf<string predicate, CCAction A> : CCPredicateAction<A> { 36 string Predicate = predicate; 37} 38 39/// CCIfByVal - If the current argument has ByVal parameter attribute, apply 40/// Action A. 41class CCIfByVal<CCAction A> : CCIf<"ArgFlags.isByVal()", A> { 42} 43 44/// CCIfPreallocated - If the current argument has Preallocated parameter attribute, 45/// apply Action A. 46class CCIfPreallocated<CCAction A> : CCIf<"ArgFlags.isPreallocated()", A> { 47} 48 49/// CCIfSwiftSelf - If the current argument has swiftself parameter attribute, 50/// apply Action A. 51class CCIfSwiftSelf<CCAction A> : CCIf<"ArgFlags.isSwiftSelf()", A> { 52} 53 54/// CCIfSwiftError - If the current argument has swifterror parameter attribute, 55/// apply Action A. 56class CCIfSwiftError<CCAction A> : CCIf<"ArgFlags.isSwiftError()", A> { 57} 58 59/// CCIfCFGuardTarget - If the current argument has cfguardtarget parameter 60/// attribute, apply Action A. 61class CCIfCFGuardTarget<CCAction A> : CCIf<"ArgFlags.isCFGuardTarget()", A> { 62} 63 64/// CCIfConsecutiveRegs - If the current argument has InConsecutiveRegs 65/// parameter attribute, apply Action A. 66class CCIfConsecutiveRegs<CCAction A> : CCIf<"ArgFlags.isInConsecutiveRegs()", A> { 67} 68 69/// CCIfCC - Match if the current calling convention is 'CC'. 70class CCIfCC<string CC, CCAction A> 71 : CCIf<!strconcat("State.getCallingConv() == ", CC), A> {} 72 73/// CCIfInReg - If this argument is marked with the 'inreg' attribute, apply 74/// the specified action. 75class CCIfInReg<CCAction A> : CCIf<"ArgFlags.isInReg()", A> {} 76 77/// CCIfNest - If this argument is marked with the 'nest' attribute, apply 78/// the specified action. 79class CCIfNest<CCAction A> : CCIf<"ArgFlags.isNest()", A> {} 80 81/// CCIfSplit - If this argument is marked with the 'split' attribute, apply 82/// the specified action. 83class CCIfSplit<CCAction A> : CCIf<"ArgFlags.isSplit()", A> {} 84 85/// CCIfSRet - If this argument is marked with the 'sret' attribute, apply 86/// the specified action. 87class CCIfSRet<CCAction A> : CCIf<"ArgFlags.isSRet()", A> {} 88 89/// CCIfVarArg - If the current function is vararg - apply the action 90class CCIfVarArg<CCAction A> : CCIf<"State.isVarArg()", A> {} 91 92/// CCIfNotVarArg - If the current function is not vararg - apply the action 93class CCIfNotVarArg<CCAction A> : CCIf<"!State.isVarArg()", A> {} 94 95/// CCIfPtrAddrSpace - If the top-level parent of the current argument has 96/// pointer type in the specified address-space. 97class CCIfPtrAddrSpace<int AS, CCAction A> 98 : CCIf<"(ArgFlags.isPointer() && ArgFlags.getPointerAddrSpace() == " # AS # ")", A> {} 99 100/// CCIfPtr - If the top-level parent of the current argument had 101/// pointer type in some address-space. 102class CCIfPtr<CCAction A> : CCIf<"ArgFlags.isPointer()", A> {} 103 104/// CCAssignToReg - This action matches if there is a register in the specified 105/// list that is still available. If so, it assigns the value to the first 106/// available register and succeeds. 107class CCAssignToReg<list<Register> regList> : CCAction { 108 list<Register> RegList = regList; 109} 110 111/// CCAssignToRegWithShadow - Same as CCAssignToReg, but with list of registers 112/// which became shadowed, when some register is used. 113class CCAssignToRegWithShadow<list<Register> regList, 114 list<Register> shadowList> : CCAction { 115 list<Register> RegList = regList; 116 list<Register> ShadowRegList = shadowList; 117} 118 119/// CCAssignToStack - This action always matches: it assigns the value to a 120/// stack slot of the specified size and alignment on the stack. If size is 121/// zero then the ABI size is used; if align is zero then the ABI alignment 122/// is used - these may depend on the target or subtarget. 123class CCAssignToStack<int size, int align> : CCAction { 124 int Size = size; 125 int Align = align; 126} 127 128/// CCAssignToStackWithShadow - Same as CCAssignToStack, but with a list of 129/// registers to be shadowed. Note that, unlike CCAssignToRegWithShadow, this 130/// shadows ALL of the registers in shadowList. 131class CCAssignToStackWithShadow<int size, 132 int align, 133 list<Register> shadowList> : CCAction { 134 int Size = size; 135 int Align = align; 136 list<Register> ShadowRegList = shadowList; 137} 138 139/// CCPassByVal - This action always matches: it assigns the value to a stack 140/// slot to implement ByVal aggregate parameter passing. Size and alignment 141/// specify the minimum size and alignment for the stack slot. 142class CCPassByVal<int size, int align> : CCAction { 143 int Size = size; 144 int Align = align; 145} 146 147/// CCPromoteToType - If applied, this promotes the specified current value to 148/// the specified type. 149class CCPromoteToType<ValueType destTy> : CCAction { 150 ValueType DestTy = destTy; 151} 152 153/// CCPromoteToUpperBitsInType - If applied, this promotes the specified current 154/// value to the specified type and shifts the value into the upper bits. 155class CCPromoteToUpperBitsInType<ValueType destTy> : CCAction { 156 ValueType DestTy = destTy; 157} 158 159/// CCBitConvertToType - If applied, this bitconverts the specified current 160/// value to the specified type. 161class CCBitConvertToType<ValueType destTy> : CCAction { 162 ValueType DestTy = destTy; 163} 164 165/// CCTruncToType - If applied, this truncates the specified current value to 166/// the specified type. 167class CCTruncToType<ValueType destTy> : CCAction { 168 ValueType DestTy = destTy; 169} 170 171/// CCPassIndirect - If applied, this stores the value to stack and passes the pointer 172/// as normal argument. 173class CCPassIndirect<ValueType destTy> : CCAction { 174 ValueType DestTy = destTy; 175} 176 177/// CCDelegateTo - This action invokes the specified sub-calling-convention. It 178/// is successful if the specified CC matches. 179class CCDelegateTo<CallingConv cc> : CCAction { 180 CallingConv CC = cc; 181} 182 183/// CallingConv - An instance of this is used to define each calling convention 184/// that the target supports. 185class CallingConv<list<CCAction> actions> { 186 list<CCAction> Actions = actions; 187 188 /// If true, this calling convention will be emitted as externally visible in 189 /// the llvm namespaces instead of as a static function. 190 bit Entry = false; 191 192 bit Custom = false; 193} 194 195/// CustomCallingConv - An instance of this is used to declare calling 196/// conventions that are implemented using a custom function of the same name. 197class CustomCallingConv : CallingConv<[]> { 198 let Custom = true; 199} 200 201/// CalleeSavedRegs - A list of callee saved registers for a given calling 202/// convention. The order of registers is used by PrologEpilogInsertion when 203/// allocation stack slots for saved registers. 204/// 205/// For each CalleeSavedRegs def, TableGen will emit a FOO_SaveList array for 206/// returning from getCalleeSavedRegs(), and a FOO_RegMask bit mask suitable for 207/// returning from getCallPreservedMask(). 208class CalleeSavedRegs<dag saves> { 209 dag SaveList = saves; 210 211 // Registers that are also preserved across function calls, but should not be 212 // included in the generated FOO_SaveList array. These registers will be 213 // included in the FOO_RegMask bit mask. This can be used for registers that 214 // are saved automatically, like the SPARC register windows. 215 dag OtherPreserved; 216} 217