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