TargetCallingConv.td 8.1 KB

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