CodeGenIntrinsics.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. //===- CodeGenIntrinsic.h - Intrinsic Class Wrapper ------------*- C++ -*--===//
  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 a wrapper class for the 'Intrinsic' TableGen class.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_UTILS_TABLEGEN_CODEGENINTRINSICS_H
  13. #define LLVM_UTILS_TABLEGEN_CODEGENINTRINSICS_H
  14. #include "SDNodeProperties.h"
  15. #include "llvm/Support/MachineValueType.h"
  16. #include <string>
  17. #include <vector>
  18. namespace llvm {
  19. class Record;
  20. class RecordKeeper;
  21. struct CodeGenIntrinsic {
  22. Record *TheDef; // The actual record defining this intrinsic.
  23. std::string Name; // The name of the LLVM function "llvm.bswap.i32"
  24. std::string EnumName; // The name of the enum "bswap_i32"
  25. std::string GCCBuiltinName; // Name of the corresponding GCC builtin, or "".
  26. std::string MSBuiltinName; // Name of the corresponding MS builtin, or "".
  27. std::string TargetPrefix; // Target prefix, e.g. "ppc" for t-s intrinsics.
  28. /// This structure holds the return values and parameter values of an
  29. /// intrinsic. If the number of return values is > 1, then the intrinsic
  30. /// implicitly returns a first-class aggregate. The numbering of the types
  31. /// starts at 0 with the first return value and continues from there through
  32. /// the parameter list. This is useful for "matching" types.
  33. struct IntrinsicSignature {
  34. /// The MVT::SimpleValueType for each return type. Note that this list is
  35. /// only populated when in the context of a target .td file. When building
  36. /// Intrinsics.td, this isn't available, because we don't know the target
  37. /// pointer size.
  38. std::vector<MVT::SimpleValueType> RetVTs;
  39. /// The records for each return type.
  40. std::vector<Record *> RetTypeDefs;
  41. /// The MVT::SimpleValueType for each parameter type. Note that this list is
  42. /// only populated when in the context of a target .td file. When building
  43. /// Intrinsics.td, this isn't available, because we don't know the target
  44. /// pointer size.
  45. std::vector<MVT::SimpleValueType> ParamVTs;
  46. /// The records for each parameter type.
  47. std::vector<Record *> ParamTypeDefs;
  48. };
  49. IntrinsicSignature IS;
  50. /// Bit flags describing the type (ref/mod) and location of memory
  51. /// accesses that may be performed by the intrinsics. Analogous to
  52. /// \c FunctionModRefBehaviour.
  53. enum ModRefBits {
  54. /// The intrinsic may access memory that is otherwise inaccessible via
  55. /// LLVM IR.
  56. MR_InaccessibleMem = 1,
  57. /// The intrinsic may access memory through pointer arguments.
  58. /// LLVM IR.
  59. MR_ArgMem = 2,
  60. /// The intrinsic may access memory anywhere, i.e. it is not restricted
  61. /// to access through pointer arguments.
  62. MR_Anywhere = 4 | MR_ArgMem | MR_InaccessibleMem,
  63. /// The intrinsic may read memory.
  64. MR_Ref = 8,
  65. /// The intrinsic may write memory.
  66. MR_Mod = 16,
  67. /// The intrinsic may both read and write memory.
  68. MR_ModRef = MR_Ref | MR_Mod,
  69. };
  70. /// Memory mod/ref behavior of this intrinsic, corresponding to intrinsic
  71. /// properties (IntrReadMem, IntrArgMemOnly, etc.).
  72. enum ModRefBehavior {
  73. NoMem = 0,
  74. ReadArgMem = MR_Ref | MR_ArgMem,
  75. ReadInaccessibleMem = MR_Ref | MR_InaccessibleMem,
  76. ReadInaccessibleMemOrArgMem = MR_Ref | MR_ArgMem | MR_InaccessibleMem,
  77. ReadMem = MR_Ref | MR_Anywhere,
  78. WriteArgMem = MR_Mod | MR_ArgMem,
  79. WriteInaccessibleMem = MR_Mod | MR_InaccessibleMem,
  80. WriteInaccessibleMemOrArgMem = MR_Mod | MR_ArgMem | MR_InaccessibleMem,
  81. WriteMem = MR_Mod | MR_Anywhere,
  82. ReadWriteArgMem = MR_ModRef | MR_ArgMem,
  83. ReadWriteInaccessibleMem = MR_ModRef | MR_InaccessibleMem,
  84. ReadWriteInaccessibleMemOrArgMem = MR_ModRef | MR_ArgMem |
  85. MR_InaccessibleMem,
  86. ReadWriteMem = MR_ModRef | MR_Anywhere,
  87. };
  88. ModRefBehavior ModRef;
  89. /// SDPatternOperator Properties applied to the intrinsic.
  90. unsigned Properties;
  91. /// This is set to true if the intrinsic is overloaded by its argument
  92. /// types.
  93. bool isOverloaded;
  94. /// True if the intrinsic is commutative.
  95. bool isCommutative;
  96. /// True if the intrinsic can throw.
  97. bool canThrow;
  98. /// True if the intrinsic is marked as noduplicate.
  99. bool isNoDuplicate;
  100. /// True if the intrinsic is marked as nomerge.
  101. bool isNoMerge;
  102. /// True if the intrinsic is no-return.
  103. bool isNoReturn;
  104. /// True if the intrinsic is no-sync.
  105. bool isNoSync;
  106. /// True if the intrinsic is no-free.
  107. bool isNoFree;
  108. /// True if the intrinsic is will-return.
  109. bool isWillReturn;
  110. /// True if the intrinsic is cold.
  111. bool isCold;
  112. /// True if the intrinsic is marked as convergent.
  113. bool isConvergent;
  114. /// True if the intrinsic has side effects that aren't captured by any
  115. /// of the other flags.
  116. bool hasSideEffects;
  117. // True if the intrinsic is marked as speculatable.
  118. bool isSpeculatable;
  119. enum ArgAttrKind {
  120. NoCapture,
  121. NoAlias,
  122. NoUndef,
  123. Returned,
  124. ReadOnly,
  125. WriteOnly,
  126. ReadNone,
  127. ImmArg,
  128. Alignment
  129. };
  130. struct ArgAttribute {
  131. unsigned Index;
  132. ArgAttrKind Kind;
  133. uint64_t Value;
  134. ArgAttribute(unsigned Idx, ArgAttrKind K, uint64_t V)
  135. : Index(Idx), Kind(K), Value(V) {}
  136. bool operator<(const ArgAttribute &Other) const {
  137. return std::tie(Index, Kind, Value) <
  138. std::tie(Other.Index, Other.Kind, Other.Value);
  139. }
  140. };
  141. std::vector<ArgAttribute> ArgumentAttributes;
  142. bool hasProperty(enum SDNP Prop) const {
  143. return Properties & (1 << Prop);
  144. }
  145. /// Goes through all IntrProperties that have IsDefault
  146. /// value set and sets the property.
  147. void setDefaultProperties(Record *R, std::vector<Record *> DefaultProperties);
  148. /// Helper function to set property \p Name to true;
  149. void setProperty(Record *R);
  150. /// Returns true if the parameter at \p ParamIdx is a pointer type. Returns
  151. /// false if the parameter is not a pointer, or \p ParamIdx is greater than
  152. /// the size of \p IS.ParamVTs.
  153. ///
  154. /// Note that this requires that \p IS.ParamVTs is available.
  155. bool isParamAPointer(unsigned ParamIdx) const;
  156. bool isParamImmArg(unsigned ParamIdx) const;
  157. CodeGenIntrinsic(Record *R, std::vector<Record *> DefaultProperties);
  158. };
  159. class CodeGenIntrinsicTable {
  160. std::vector<CodeGenIntrinsic> Intrinsics;
  161. public:
  162. struct TargetSet {
  163. std::string Name;
  164. size_t Offset;
  165. size_t Count;
  166. };
  167. std::vector<TargetSet> Targets;
  168. explicit CodeGenIntrinsicTable(const RecordKeeper &RC);
  169. CodeGenIntrinsicTable() = default;
  170. bool empty() const { return Intrinsics.empty(); }
  171. size_t size() const { return Intrinsics.size(); }
  172. CodeGenIntrinsic &operator[](size_t Pos) { return Intrinsics[Pos]; }
  173. const CodeGenIntrinsic &operator[](size_t Pos) const {
  174. return Intrinsics[Pos];
  175. }
  176. };
  177. }
  178. #endif