TargetCallingConv.td 8.2 KB

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