CodeGenIntrinsics.h 6.9 KB

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