Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line | 
|---|---|---|---|
| 14 | pmbaty | 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 | |||
| 14 | class CCAction; | ||
| 15 | class CallingConv; | ||
| 16 | |||
| 17 | /// CCCustom - Calls a custom arg handling function. | ||
| 18 | class 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. | ||
| 24 | class 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. | ||
| 30 | class CCIfType<list<ValueType> vts, CCAction A> : CCPredicateAction<A> { | ||
| 31 | list<ValueType> VTs = vts; | ||
| 32 | } | ||
| 33 | |||
| 34 | /// CCIf - If the predicate matches, apply A. | ||
| 35 | class 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. | ||
| 41 | class CCIfByVal<CCAction A> : CCIf<"ArgFlags.isByVal()", A> { | ||
| 42 | } | ||
| 43 | |||
| 44 | /// CCIfPreallocated - If the current argument has Preallocated parameter attribute, | ||
| 45 | /// apply Action A. | ||
| 46 | class CCIfPreallocated<CCAction A> : CCIf<"ArgFlags.isPreallocated()", A> { | ||
| 47 | } | ||
| 48 | |||
| 49 | /// CCIfSwiftSelf - If the current argument has swiftself parameter attribute, | ||
| 50 | /// apply Action A. | ||
| 51 | class CCIfSwiftSelf<CCAction A> : CCIf<"ArgFlags.isSwiftSelf()", A> { | ||
| 52 | } | ||
| 53 | |||
| 54 | /// CCIfSwiftAsync - If the current argument has swiftasync parameter attribute, | ||
| 55 | /// apply Action A. | ||
| 56 | class CCIfSwiftAsync<CCAction A> : CCIf<"ArgFlags.isSwiftAsync()", A> { | ||
| 57 | } | ||
| 58 | |||
| 59 | /// CCIfSwiftError - If the current argument has swifterror parameter attribute, | ||
| 60 | /// apply Action A. | ||
| 61 | class CCIfSwiftError<CCAction A> : CCIf<"ArgFlags.isSwiftError()", A> { | ||
| 62 | } | ||
| 63 | |||
| 64 | /// CCIfCFGuardTarget - If the current argument has cfguardtarget parameter | ||
| 65 | /// attribute, apply Action A. | ||
| 66 | class CCIfCFGuardTarget<CCAction A> : CCIf<"ArgFlags.isCFGuardTarget()", A> { | ||
| 67 | } | ||
| 68 | |||
| 69 | /// CCIfConsecutiveRegs - If the current argument has InConsecutiveRegs | ||
| 70 | /// parameter attribute, apply Action A. | ||
| 71 | class CCIfConsecutiveRegs<CCAction A> : CCIf<"ArgFlags.isInConsecutiveRegs()", A> { | ||
| 72 | } | ||
| 73 | |||
| 74 | /// CCIfCC - Match if the current calling convention is 'CC'. | ||
| 75 | class 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. | ||
| 80 | class CCIfInReg<CCAction A> : CCIf<"ArgFlags.isInReg()", A> {} | ||
| 81 | |||
| 82 | /// CCIfNest - If this argument is marked with the 'nest' attribute, apply | ||
| 83 | /// the specified action. | ||
| 84 | class CCIfNest<CCAction A> : CCIf<"ArgFlags.isNest()", A> {} | ||
| 85 | |||
| 86 | /// CCIfSplit - If this argument is marked with the 'split' attribute, apply | ||
| 87 | /// the specified action. | ||
| 88 | class CCIfSplit<CCAction A> : CCIf<"ArgFlags.isSplit()", A> {} | ||
| 89 | |||
| 90 | /// CCIfSRet - If this argument is marked with the 'sret' attribute, apply | ||
| 91 | /// the specified action. | ||
| 92 | class CCIfSRet<CCAction A> : CCIf<"ArgFlags.isSRet()", A> {} | ||
| 93 | |||
| 94 | /// CCIfVarArg - If the current function is vararg - apply the action | ||
| 95 | class CCIfVarArg<CCAction A> : CCIf<"State.isVarArg()", A> {} | ||
| 96 | |||
| 97 | /// CCIfNotVarArg - If the current function is not vararg - apply the action | ||
| 98 | class 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. | ||
| 102 | class 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. | ||
| 107 | class 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. | ||
| 112 | class 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. | ||
| 118 | class 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. | ||
| 128 | class 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. | ||
| 136 | class 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 | /// CCAssignToRegAndStack - Same as CCAssignToReg, but also allocates a stack | ||
| 145 | /// slot, when some register is used. Basically, it works like: | ||
| 146 | /// CCIf<CCAssignToReg<regList>, CCAssignToStack<size, align>>. | ||
| 147 | class CCAssignToRegAndStack<list<Register> regList, int size, int align> | ||
| 148 |     : CCAssignToReg<regList> { | ||
| 149 | int Size = size; | ||
| 150 | int Align = align; | ||
| 151 | } | ||
| 152 | |||
| 153 | /// CCPassByVal - This action always matches: it assigns the value to a stack | ||
| 154 | /// slot to implement ByVal aggregate parameter passing. Size and alignment | ||
| 155 | /// specify the minimum size and alignment for the stack slot. | ||
| 156 | class CCPassByVal<int size, int align> : CCAction { | ||
| 157 | int Size = size; | ||
| 158 | int Align = align; | ||
| 159 | } | ||
| 160 | |||
| 161 | /// CCPromoteToType - If applied, this promotes the specified current value to | ||
| 162 | /// the specified type. | ||
| 163 | class CCPromoteToType<ValueType destTy> : CCAction { | ||
| 164 | ValueType DestTy = destTy; | ||
| 165 | } | ||
| 166 | |||
| 167 | /// CCPromoteToUpperBitsInType - If applied, this promotes the specified current | ||
| 168 | /// value to the specified type and shifts the value into the upper bits. | ||
| 169 | class CCPromoteToUpperBitsInType<ValueType destTy> : CCAction { | ||
| 170 | ValueType DestTy = destTy; | ||
| 171 | } | ||
| 172 | |||
| 173 | /// CCBitConvertToType - If applied, this bitconverts the specified current | ||
| 174 | /// value to the specified type. | ||
| 175 | class CCBitConvertToType<ValueType destTy> : CCAction { | ||
| 176 | ValueType DestTy = destTy; | ||
| 177 | } | ||
| 178 | |||
| 179 | /// CCTruncToType - If applied, this truncates the specified current value to | ||
| 180 | /// the specified type. | ||
| 181 | class CCTruncToType<ValueType destTy> : CCAction { | ||
| 182 | ValueType DestTy = destTy; | ||
| 183 | } | ||
| 184 | |||
| 185 | /// CCPassIndirect - If applied, this stores the value to stack and passes the pointer | ||
| 186 | /// as normal argument. | ||
| 187 | class CCPassIndirect<ValueType destTy> : CCAction { | ||
| 188 | ValueType DestTy = destTy; | ||
| 189 | } | ||
| 190 | |||
| 191 | /// CCDelegateTo - This action invokes the specified sub-calling-convention. It | ||
| 192 | /// is successful if the specified CC matches. | ||
| 193 | class CCDelegateTo<CallingConv cc> : CCAction { | ||
| 194 | CallingConv CC = cc; | ||
| 195 | } | ||
| 196 | |||
| 197 | /// CallingConv - An instance of this is used to define each calling convention | ||
| 198 | /// that the target supports. | ||
| 199 | class CallingConv<list<CCAction> actions> { | ||
| 200 | list<CCAction> Actions = actions; | ||
| 201 | |||
| 202 | /// If true, this calling convention will be emitted as externally visible in | ||
| 203 | /// the llvm namespaces instead of as a static function. | ||
| 204 | bit Entry = false; | ||
| 205 | |||
| 206 | bit Custom = false; | ||
| 207 | } | ||
| 208 | |||
| 209 | /// CustomCallingConv - An instance of this is used to declare calling | ||
| 210 | /// conventions that are implemented using a custom function of the same name. | ||
| 211 | class CustomCallingConv : CallingConv<[]> { | ||
| 212 | let Custom = true; | ||
| 213 | } | ||
| 214 | |||
| 215 | /// CalleeSavedRegs - A list of callee saved registers for a given calling | ||
| 216 | /// convention. The order of registers is used by PrologEpilogInsertion when | ||
| 217 | /// allocation stack slots for saved registers. | ||
| 218 | /// | ||
| 219 | /// For each CalleeSavedRegs def, TableGen will emit a FOO_SaveList array for | ||
| 220 | /// returning from getCalleeSavedRegs(), and a FOO_RegMask bit mask suitable for | ||
| 221 | /// returning from getCallPreservedMask(). | ||
| 222 | class CalleeSavedRegs<dag saves> { | ||
| 223 | dag SaveList = saves; | ||
| 224 | |||
| 225 | // Registers that are also preserved across function calls, but should not be | ||
| 226 | // included in the generated FOO_SaveList array. These registers will be | ||
| 227 | // included in the FOO_RegMask bit mask. This can be used for registers that | ||
| 228 | // are saved automatically, like the SPARC register windows. | ||
| 229 | dag OtherPreserved; | ||
| 230 | } |