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