TargetCallingConv.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. //===-- llvm/Target/TargetCallingConv.h - Calling Convention ----*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file defines types for working with calling-convention information.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_TARGET_TARGETCALLINGCONV_H
  14. #define LLVM_TARGET_TARGETCALLINGCONV_H
  15. #include "llvm/CodeGen/ValueTypes.h"
  16. #include "llvm/Support/DataTypes.h"
  17. #include "llvm/Support/MathExtras.h"
  18. #include <string>
  19. #include <limits.h>
  20. namespace llvm {
  21. namespace ISD {
  22. struct ArgFlagsTy {
  23. private:
  24. static const uint64_t NoFlagSet = 0ULL;
  25. static const uint64_t ZExt = 1ULL<<0; ///< Zero extended
  26. static const uint64_t ZExtOffs = 0;
  27. static const uint64_t SExt = 1ULL<<1; ///< Sign extended
  28. static const uint64_t SExtOffs = 1;
  29. static const uint64_t InReg = 1ULL<<2; ///< Passed in register
  30. static const uint64_t InRegOffs = 2;
  31. static const uint64_t SRet = 1ULL<<3; ///< Hidden struct-ret ptr
  32. static const uint64_t SRetOffs = 3;
  33. static const uint64_t ByVal = 1ULL<<4; ///< Struct passed by value
  34. static const uint64_t ByValOffs = 4;
  35. static const uint64_t Nest = 1ULL<<5; ///< Nested fn static chain
  36. static const uint64_t NestOffs = 5;
  37. static const uint64_t Returned = 1ULL<<6; ///< Always returned
  38. static const uint64_t ReturnedOffs = 6;
  39. static const uint64_t ByValAlign = 0xFULL<<7; ///< Struct alignment
  40. static const uint64_t ByValAlignOffs = 7;
  41. static const uint64_t Split = 1ULL<<11;
  42. static const uint64_t SplitOffs = 11;
  43. static const uint64_t InAlloca = 1ULL<<12; ///< Passed with inalloca
  44. static const uint64_t InAllocaOffs = 12;
  45. static const uint64_t OrigAlign = 0x1FULL<<27;
  46. static const uint64_t OrigAlignOffs = 27;
  47. static const uint64_t ByValSize = 0x3fffffffULL<<32; ///< Struct size
  48. static const uint64_t ByValSizeOffs = 32;
  49. static const uint64_t InConsecutiveRegsLast = 0x1ULL<<62; ///< Struct size
  50. static const uint64_t InConsecutiveRegsLastOffs = 62;
  51. static const uint64_t InConsecutiveRegs = 0x1ULL<<63; ///< Struct size
  52. static const uint64_t InConsecutiveRegsOffs = 63;
  53. static const uint64_t One = 1ULL; ///< 1 of this type, for shifts
  54. uint64_t Flags;
  55. public:
  56. ArgFlagsTy() : Flags(0) { }
  57. bool isZExt() const { return Flags & ZExt; }
  58. void setZExt() { Flags |= One << ZExtOffs; }
  59. bool isSExt() const { return Flags & SExt; }
  60. void setSExt() { Flags |= One << SExtOffs; }
  61. bool isInReg() const { return Flags & InReg; }
  62. void setInReg() { Flags |= One << InRegOffs; }
  63. bool isSRet() const { return Flags & SRet; }
  64. void setSRet() { Flags |= One << SRetOffs; }
  65. bool isByVal() const { return Flags & ByVal; }
  66. void setByVal() { Flags |= One << ByValOffs; }
  67. bool isInAlloca() const { return Flags & InAlloca; }
  68. void setInAlloca() { Flags |= One << InAllocaOffs; }
  69. bool isNest() const { return Flags & Nest; }
  70. void setNest() { Flags |= One << NestOffs; }
  71. bool isReturned() const { return Flags & Returned; }
  72. void setReturned() { Flags |= One << ReturnedOffs; }
  73. bool isInConsecutiveRegs() const { return Flags & InConsecutiveRegs; }
  74. void setInConsecutiveRegs() { Flags |= One << InConsecutiveRegsOffs; }
  75. bool isInConsecutiveRegsLast() const { return Flags & InConsecutiveRegsLast; }
  76. void setInConsecutiveRegsLast() { Flags |= One << InConsecutiveRegsLastOffs; }
  77. unsigned getByValAlign() const {
  78. return (unsigned)
  79. ((One << ((Flags & ByValAlign) >> ByValAlignOffs)) / 2);
  80. }
  81. void setByValAlign(unsigned A) {
  82. Flags = (Flags & ~ByValAlign) |
  83. (uint64_t(Log2_32(A) + 1) << ByValAlignOffs);
  84. }
  85. bool isSplit() const { return Flags & Split; }
  86. void setSplit() { Flags |= One << SplitOffs; }
  87. unsigned getOrigAlign() const {
  88. return (unsigned)
  89. ((One << ((Flags & OrigAlign) >> OrigAlignOffs)) / 2);
  90. }
  91. void setOrigAlign(unsigned A) {
  92. Flags = (Flags & ~OrigAlign) |
  93. (uint64_t(Log2_32(A) + 1) << OrigAlignOffs);
  94. }
  95. unsigned getByValSize() const {
  96. return (unsigned)((Flags & ByValSize) >> ByValSizeOffs);
  97. }
  98. void setByValSize(unsigned S) {
  99. Flags = (Flags & ~ByValSize) | (uint64_t(S) << ByValSizeOffs);
  100. }
  101. /// getRawBits - Represent the flags as a bunch of bits.
  102. uint64_t getRawBits() const { return Flags; }
  103. };
  104. /// InputArg - This struct carries flags and type information about a
  105. /// single incoming (formal) argument or incoming (from the perspective
  106. /// of the caller) return value virtual register.
  107. ///
  108. struct InputArg {
  109. ArgFlagsTy Flags;
  110. MVT VT;
  111. EVT ArgVT;
  112. bool Used;
  113. /// Index original Function's argument.
  114. unsigned OrigArgIndex;
  115. /// Sentinel value for implicit machine-level input arguments.
  116. static const unsigned NoArgIndex = UINT_MAX;
  117. /// Offset in bytes of current input value relative to the beginning of
  118. /// original argument. E.g. if argument was splitted into four 32 bit
  119. /// registers, we got 4 InputArgs with PartOffsets 0, 4, 8 and 12.
  120. unsigned PartOffset;
  121. InputArg() : VT(MVT::Other), Used(false) {}
  122. InputArg(ArgFlagsTy flags, EVT vt, EVT argvt, bool used,
  123. unsigned origIdx, unsigned partOffs)
  124. : Flags(flags), Used(used), OrigArgIndex(origIdx), PartOffset(partOffs) {
  125. VT = vt.getSimpleVT();
  126. ArgVT = argvt;
  127. }
  128. bool isOrigArg() const {
  129. return OrigArgIndex != NoArgIndex;
  130. }
  131. unsigned getOrigArgIndex() const {
  132. assert(OrigArgIndex != NoArgIndex && "Implicit machine-level argument");
  133. return OrigArgIndex;
  134. }
  135. };
  136. /// OutputArg - This struct carries flags and a value for a
  137. /// single outgoing (actual) argument or outgoing (from the perspective
  138. /// of the caller) return value virtual register.
  139. ///
  140. struct OutputArg {
  141. ArgFlagsTy Flags;
  142. MVT VT;
  143. EVT ArgVT;
  144. /// IsFixed - Is this a "fixed" value, ie not passed through a vararg "...".
  145. bool IsFixed;
  146. /// Index original Function's argument.
  147. unsigned OrigArgIndex;
  148. /// Offset in bytes of current output value relative to the beginning of
  149. /// original argument. E.g. if argument was splitted into four 32 bit
  150. /// registers, we got 4 OutputArgs with PartOffsets 0, 4, 8 and 12.
  151. unsigned PartOffset;
  152. OutputArg() : IsFixed(false) {}
  153. OutputArg(ArgFlagsTy flags, EVT vt, EVT argvt, bool isfixed,
  154. unsigned origIdx, unsigned partOffs)
  155. : Flags(flags), IsFixed(isfixed), OrigArgIndex(origIdx),
  156. PartOffset(partOffs) {
  157. VT = vt.getSimpleVT();
  158. ArgVT = argvt;
  159. }
  160. };
  161. }
  162. } // end llvm namespace
  163. #endif