CodeGenIntrinsics.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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/ADT/SmallVector.h"
  16. #include "llvm/Support/MachineValueType.h"
  17. #include "llvm/Support/ModRef.h"
  18. #include <string>
  19. #include <vector>
  20. namespace llvm {
  21. class Record;
  22. class RecordKeeper;
  23. struct CodeGenIntrinsic {
  24. Record *TheDef; // The actual record defining this intrinsic.
  25. std::string Name; // The name of the LLVM function "llvm.bswap.i32"
  26. std::string EnumName; // The name of the enum "bswap_i32"
  27. std::string ClangBuiltinName; // Name of the corresponding GCC builtin, or "".
  28. std::string MSBuiltinName; // Name of the corresponding MS builtin, or "".
  29. std::string TargetPrefix; // Target prefix, e.g. "ppc" for t-s intrinsics.
  30. /// This structure holds the return values and parameter values of an
  31. /// intrinsic. If the number of return values is > 1, then the intrinsic
  32. /// implicitly returns a first-class aggregate. The numbering of the types
  33. /// starts at 0 with the first return value and continues from there through
  34. /// the parameter list. This is useful for "matching" types.
  35. struct IntrinsicSignature {
  36. /// The MVT::SimpleValueType for each return type. Note that this list is
  37. /// only populated when in the context of a target .td file. When building
  38. /// Intrinsics.td, this isn't available, because we don't know the target
  39. /// pointer size.
  40. std::vector<MVT::SimpleValueType> RetVTs;
  41. /// The records for each return type.
  42. std::vector<Record *> RetTypeDefs;
  43. /// The MVT::SimpleValueType for each parameter type. Note that this list is
  44. /// only populated when in the context of a target .td file. When building
  45. /// Intrinsics.td, this isn't available, because we don't know the target
  46. /// pointer size.
  47. std::vector<MVT::SimpleValueType> ParamVTs;
  48. /// The records for each parameter type.
  49. std::vector<Record *> ParamTypeDefs;
  50. };
  51. IntrinsicSignature IS;
  52. /// Memory effects of the intrinsic.
  53. MemoryEffects ME = MemoryEffects::unknown();
  54. /// SDPatternOperator Properties applied to the intrinsic.
  55. unsigned Properties;
  56. /// This is set to true if the intrinsic is overloaded by its argument
  57. /// types.
  58. bool isOverloaded;
  59. /// True if the intrinsic is commutative.
  60. bool isCommutative;
  61. /// True if the intrinsic can throw.
  62. bool canThrow;
  63. /// True if the intrinsic is marked as noduplicate.
  64. bool isNoDuplicate;
  65. /// True if the intrinsic is marked as nomerge.
  66. bool isNoMerge;
  67. /// True if the intrinsic is no-return.
  68. bool isNoReturn;
  69. /// True if the intrinsic is no-callback.
  70. bool isNoCallback;
  71. /// True if the intrinsic is no-sync.
  72. bool isNoSync;
  73. /// True if the intrinsic is no-free.
  74. bool isNoFree;
  75. /// True if the intrinsic is will-return.
  76. bool isWillReturn;
  77. /// True if the intrinsic is cold.
  78. bool isCold;
  79. /// True if the intrinsic is marked as convergent.
  80. bool isConvergent;
  81. /// True if the intrinsic has side effects that aren't captured by any
  82. /// of the other flags.
  83. bool hasSideEffects;
  84. // True if the intrinsic is marked as speculatable.
  85. bool isSpeculatable;
  86. enum ArgAttrKind {
  87. NoCapture,
  88. NoAlias,
  89. NoUndef,
  90. NonNull,
  91. Returned,
  92. ReadOnly,
  93. WriteOnly,
  94. ReadNone,
  95. ImmArg,
  96. Alignment
  97. };
  98. struct ArgAttribute {
  99. ArgAttrKind Kind;
  100. uint64_t Value;
  101. ArgAttribute(ArgAttrKind K, uint64_t V) : Kind(K), Value(V) {}
  102. bool operator<(const ArgAttribute &Other) const {
  103. return std::tie(Kind, Value) < std::tie(Other.Kind, Other.Value);
  104. }
  105. };
  106. /// Vector of attributes for each argument.
  107. SmallVector<SmallVector<ArgAttribute, 0>> ArgumentAttributes;
  108. void addArgAttribute(unsigned Idx, ArgAttrKind AK, uint64_t V = 0);
  109. bool hasProperty(enum SDNP Prop) const {
  110. return Properties & (1 << Prop);
  111. }
  112. /// Goes through all IntrProperties that have IsDefault
  113. /// value set and sets the property.
  114. void setDefaultProperties(Record *R, std::vector<Record *> DefaultProperties);
  115. /// Helper function to set property \p Name to true;
  116. void setProperty(Record *R);
  117. /// Returns true if the parameter at \p ParamIdx is a pointer type. Returns
  118. /// false if the parameter is not a pointer, or \p ParamIdx is greater than
  119. /// the size of \p IS.ParamVTs.
  120. ///
  121. /// Note that this requires that \p IS.ParamVTs is available.
  122. bool isParamAPointer(unsigned ParamIdx) const;
  123. bool isParamImmArg(unsigned ParamIdx) const;
  124. CodeGenIntrinsic(Record *R, std::vector<Record *> DefaultProperties);
  125. };
  126. class CodeGenIntrinsicTable {
  127. std::vector<CodeGenIntrinsic> Intrinsics;
  128. public:
  129. struct TargetSet {
  130. std::string Name;
  131. size_t Offset;
  132. size_t Count;
  133. };
  134. std::vector<TargetSet> Targets;
  135. explicit CodeGenIntrinsicTable(const RecordKeeper &RC);
  136. CodeGenIntrinsicTable() = default;
  137. bool empty() const { return Intrinsics.empty(); }
  138. size_t size() const { return Intrinsics.size(); }
  139. auto begin() const { return Intrinsics.begin(); }
  140. auto end() const { return Intrinsics.end(); }
  141. CodeGenIntrinsic &operator[](size_t Pos) { return Intrinsics[Pos]; }
  142. const CodeGenIntrinsic &operator[](size_t Pos) const {
  143. return Intrinsics[Pos];
  144. }
  145. };
  146. }
  147. #endif