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