TargetCallingConv.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-- llvm/CodeGen/TargetCallingConv.h - Calling Convention ---*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file defines types for working with calling-convention information.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_CODEGEN_TARGETCALLINGCONV_H
  18. #define LLVM_CODEGEN_TARGETCALLINGCONV_H
  19. #include "llvm/CodeGen/ValueTypes.h"
  20. #include "llvm/Support/Alignment.h"
  21. #include "llvm/Support/MachineValueType.h"
  22. #include "llvm/Support/MathExtras.h"
  23. #include <cassert>
  24. #include <climits>
  25. #include <cstdint>
  26. namespace llvm {
  27. namespace ISD {
  28. struct ArgFlagsTy {
  29. private:
  30. unsigned IsZExt : 1; ///< Zero extended
  31. unsigned IsSExt : 1; ///< Sign extended
  32. unsigned IsInReg : 1; ///< Passed in register
  33. unsigned IsSRet : 1; ///< Hidden struct-ret ptr
  34. unsigned IsByVal : 1; ///< Struct passed by value
  35. unsigned IsByRef : 1; ///< Passed in memory
  36. unsigned IsNest : 1; ///< Nested fn static chain
  37. unsigned IsReturned : 1; ///< Always returned
  38. unsigned IsSplit : 1;
  39. unsigned IsInAlloca : 1; ///< Passed with inalloca
  40. unsigned IsPreallocated : 1; ///< ByVal without the copy
  41. unsigned IsSplitEnd : 1; ///< Last part of a split
  42. unsigned IsSwiftSelf : 1; ///< Swift self parameter
  43. unsigned IsSwiftAsync : 1; ///< Swift async context parameter
  44. unsigned IsSwiftError : 1; ///< Swift error parameter
  45. unsigned IsCFGuardTarget : 1; ///< Control Flow Guard target
  46. unsigned IsHva : 1; ///< HVA field for
  47. unsigned IsHvaStart : 1; ///< HVA structure start
  48. unsigned IsSecArgPass : 1; ///< Second argument
  49. unsigned MemAlign : 4; ///< Log 2 of alignment when arg is passed in memory
  50. ///< (including byval/byref)
  51. unsigned OrigAlign : 5; ///< Log 2 of original alignment
  52. unsigned IsInConsecutiveRegsLast : 1;
  53. unsigned IsInConsecutiveRegs : 1;
  54. unsigned IsCopyElisionCandidate : 1; ///< Argument copy elision candidate
  55. unsigned IsPointer : 1;
  56. unsigned ByValOrByRefSize = 0; ///< Byval or byref struct size
  57. unsigned PointerAddrSpace = 0; ///< Address space of pointer argument
  58. public:
  59. ArgFlagsTy()
  60. : IsZExt(0), IsSExt(0), IsInReg(0), IsSRet(0), IsByVal(0), IsByRef(0),
  61. IsNest(0), IsReturned(0), IsSplit(0), IsInAlloca(0),
  62. IsPreallocated(0), IsSplitEnd(0), IsSwiftSelf(0), IsSwiftAsync(0),
  63. IsSwiftError(0), IsCFGuardTarget(0), IsHva(0), IsHvaStart(0),
  64. IsSecArgPass(0), MemAlign(0), OrigAlign(0),
  65. IsInConsecutiveRegsLast(0), IsInConsecutiveRegs(0),
  66. IsCopyElisionCandidate(0), IsPointer(0) {
  67. static_assert(sizeof(*this) == 3 * sizeof(unsigned), "flags are too big");
  68. }
  69. bool isZExt() const { return IsZExt; }
  70. void setZExt() { IsZExt = 1; }
  71. bool isSExt() const { return IsSExt; }
  72. void setSExt() { IsSExt = 1; }
  73. bool isInReg() const { return IsInReg; }
  74. void setInReg() { IsInReg = 1; }
  75. bool isSRet() const { return IsSRet; }
  76. void setSRet() { IsSRet = 1; }
  77. bool isByVal() const { return IsByVal; }
  78. void setByVal() { IsByVal = 1; }
  79. bool isByRef() const { return IsByRef; }
  80. void setByRef() { IsByRef = 1; }
  81. bool isInAlloca() const { return IsInAlloca; }
  82. void setInAlloca() { IsInAlloca = 1; }
  83. bool isPreallocated() const { return IsPreallocated; }
  84. void setPreallocated() { IsPreallocated = 1; }
  85. bool isSwiftSelf() const { return IsSwiftSelf; }
  86. void setSwiftSelf() { IsSwiftSelf = 1; }
  87. bool isSwiftAsync() const { return IsSwiftAsync; }
  88. void setSwiftAsync() { IsSwiftAsync = 1; }
  89. bool isSwiftError() const { return IsSwiftError; }
  90. void setSwiftError() { IsSwiftError = 1; }
  91. bool isCFGuardTarget() const { return IsCFGuardTarget; }
  92. void setCFGuardTarget() { IsCFGuardTarget = 1; }
  93. bool isHva() const { return IsHva; }
  94. void setHva() { IsHva = 1; }
  95. bool isHvaStart() const { return IsHvaStart; }
  96. void setHvaStart() { IsHvaStart = 1; }
  97. bool isSecArgPass() const { return IsSecArgPass; }
  98. void setSecArgPass() { IsSecArgPass = 1; }
  99. bool isNest() const { return IsNest; }
  100. void setNest() { IsNest = 1; }
  101. bool isReturned() const { return IsReturned; }
  102. void setReturned(bool V = true) { IsReturned = V; }
  103. bool isInConsecutiveRegs() const { return IsInConsecutiveRegs; }
  104. void setInConsecutiveRegs(bool Flag = true) { IsInConsecutiveRegs = Flag; }
  105. bool isInConsecutiveRegsLast() const { return IsInConsecutiveRegsLast; }
  106. void setInConsecutiveRegsLast(bool Flag = true) {
  107. IsInConsecutiveRegsLast = Flag;
  108. }
  109. bool isSplit() const { return IsSplit; }
  110. void setSplit() { IsSplit = 1; }
  111. bool isSplitEnd() const { return IsSplitEnd; }
  112. void setSplitEnd() { IsSplitEnd = 1; }
  113. bool isCopyElisionCandidate() const { return IsCopyElisionCandidate; }
  114. void setCopyElisionCandidate() { IsCopyElisionCandidate = 1; }
  115. bool isPointer() const { return IsPointer; }
  116. void setPointer() { IsPointer = 1; }
  117. Align getNonZeroMemAlign() const {
  118. return decodeMaybeAlign(MemAlign).valueOrOne();
  119. }
  120. void setMemAlign(Align A) {
  121. MemAlign = encode(A);
  122. assert(getNonZeroMemAlign() == A && "bitfield overflow");
  123. }
  124. Align getNonZeroByValAlign() const {
  125. assert(isByVal());
  126. MaybeAlign A = decodeMaybeAlign(MemAlign);
  127. assert(A && "ByValAlign must be defined");
  128. return *A;
  129. }
  130. Align getNonZeroOrigAlign() const {
  131. return decodeMaybeAlign(OrigAlign).valueOrOne();
  132. }
  133. void setOrigAlign(Align A) {
  134. OrigAlign = encode(A);
  135. assert(getNonZeroOrigAlign() == A && "bitfield overflow");
  136. }
  137. unsigned getByValSize() const {
  138. assert(isByVal() && !isByRef());
  139. return ByValOrByRefSize;
  140. }
  141. void setByValSize(unsigned S) {
  142. assert(isByVal() && !isByRef());
  143. ByValOrByRefSize = S;
  144. }
  145. unsigned getByRefSize() const {
  146. assert(!isByVal() && isByRef());
  147. return ByValOrByRefSize;
  148. }
  149. void setByRefSize(unsigned S) {
  150. assert(!isByVal() && isByRef());
  151. ByValOrByRefSize = S;
  152. }
  153. unsigned getPointerAddrSpace() const { return PointerAddrSpace; }
  154. void setPointerAddrSpace(unsigned AS) { PointerAddrSpace = AS; }
  155. };
  156. /// InputArg - This struct carries flags and type information about a
  157. /// single incoming (formal) argument or incoming (from the perspective
  158. /// of the caller) return value virtual register.
  159. ///
  160. struct InputArg {
  161. ArgFlagsTy Flags;
  162. MVT VT = MVT::Other;
  163. EVT ArgVT;
  164. bool Used = false;
  165. /// Index original Function's argument.
  166. unsigned OrigArgIndex;
  167. /// Sentinel value for implicit machine-level input arguments.
  168. static const unsigned NoArgIndex = UINT_MAX;
  169. /// Offset in bytes of current input value relative to the beginning of
  170. /// original argument. E.g. if argument was splitted into four 32 bit
  171. /// registers, we got 4 InputArgs with PartOffsets 0, 4, 8 and 12.
  172. unsigned PartOffset;
  173. InputArg() = default;
  174. InputArg(ArgFlagsTy flags, EVT vt, EVT argvt, bool used,
  175. unsigned origIdx, unsigned partOffs)
  176. : Flags(flags), Used(used), OrigArgIndex(origIdx), PartOffset(partOffs) {
  177. VT = vt.getSimpleVT();
  178. ArgVT = argvt;
  179. }
  180. bool isOrigArg() const {
  181. return OrigArgIndex != NoArgIndex;
  182. }
  183. unsigned getOrigArgIndex() const {
  184. assert(OrigArgIndex != NoArgIndex && "Implicit machine-level argument");
  185. return OrigArgIndex;
  186. }
  187. };
  188. /// OutputArg - This struct carries flags and a value for a
  189. /// single outgoing (actual) argument or outgoing (from the perspective
  190. /// of the caller) return value virtual register.
  191. ///
  192. struct OutputArg {
  193. ArgFlagsTy Flags;
  194. MVT VT;
  195. EVT ArgVT;
  196. /// IsFixed - Is this a "fixed" value, ie not passed through a vararg "...".
  197. bool IsFixed = false;
  198. /// Index original Function's argument.
  199. unsigned OrigArgIndex;
  200. /// Offset in bytes of current output value relative to the beginning of
  201. /// original argument. E.g. if argument was splitted into four 32 bit
  202. /// registers, we got 4 OutputArgs with PartOffsets 0, 4, 8 and 12.
  203. unsigned PartOffset;
  204. OutputArg() = default;
  205. OutputArg(ArgFlagsTy flags, MVT vt, EVT argvt, bool isfixed,
  206. unsigned origIdx, unsigned partOffs)
  207. : Flags(flags), IsFixed(isfixed), OrigArgIndex(origIdx),
  208. PartOffset(partOffs) {
  209. VT = vt;
  210. ArgVT = argvt;
  211. }
  212. };
  213. } // end namespace ISD
  214. } // end namespace llvm
  215. #endif // LLVM_CODEGEN_TARGETCALLINGCONV_H
  216. #ifdef __GNUC__
  217. #pragma GCC diagnostic pop
  218. #endif