Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

244 lines
8.4 KiB

  1. //===-- llvm/Metadata.h - Metadata definitions ------------------*- 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. /// @file
  11. /// This file contains the declarations for metadata subclasses.
  12. /// They represent the different flavors of metadata that live in LLVM.
  13. //
  14. //===----------------------------------------------------------------------===//
  15. #ifndef LLVM_METADATA_H
  16. #define LLVM_METADATA_H
  17. #include "llvm/Value.h"
  18. #include "llvm/ADT/ArrayRef.h"
  19. #include "llvm/ADT/FoldingSet.h"
  20. #include "llvm/ADT/ilist_node.h"
  21. namespace llvm {
  22. class Constant;
  23. class Instruction;
  24. class LLVMContext;
  25. class Module;
  26. template <typename T> class SmallVectorImpl;
  27. template<typename ValueSubClass, typename ItemParentClass>
  28. class SymbolTableListTraits;
  29. //===----------------------------------------------------------------------===//
  30. /// MDString - a single uniqued string.
  31. /// These are used to efficiently contain a byte sequence for metadata.
  32. /// MDString is always unnamed.
  33. class MDString : public Value {
  34. virtual void anchor();
  35. MDString(const MDString &) LLVM_DELETED_FUNCTION;
  36. explicit MDString(LLVMContext &C);
  37. public:
  38. static MDString *get(LLVMContext &Context, StringRef Str);
  39. static MDString *get(LLVMContext &Context, const char *Str) {
  40. return get(Context, Str ? StringRef(Str) : StringRef());
  41. }
  42. StringRef getString() const { return getName(); }
  43. unsigned getLength() const { return (unsigned)getName().size(); }
  44. typedef StringRef::iterator iterator;
  45. /// begin() - Pointer to the first byte of the string.
  46. iterator begin() const { return getName().begin(); }
  47. /// end() - Pointer to one byte past the end of the string.
  48. iterator end() const { return getName().end(); }
  49. /// Methods for support type inquiry through isa, cast, and dyn_cast:
  50. static inline bool classof(const MDString *) { return true; }
  51. static bool classof(const Value *V) {
  52. return V->getValueID() == MDStringVal;
  53. }
  54. };
  55. class MDNodeOperand;
  56. //===----------------------------------------------------------------------===//
  57. /// MDNode - a tuple of other values.
  58. class MDNode : public Value, public FoldingSetNode {
  59. MDNode(const MDNode &) LLVM_DELETED_FUNCTION;
  60. void operator=(const MDNode &) LLVM_DELETED_FUNCTION;
  61. friend class MDNodeOperand;
  62. friend class LLVMContextImpl;
  63. friend struct FoldingSetTrait<MDNode>;
  64. /// Hash - If the MDNode is uniqued cache the hash to speed up lookup.
  65. unsigned Hash;
  66. /// NumOperands - This many 'MDNodeOperand' items are co-allocated onto the
  67. /// end of this MDNode.
  68. unsigned NumOperands;
  69. // Subclass data enums.
  70. enum {
  71. /// FunctionLocalBit - This bit is set if this MDNode is function local.
  72. /// This is true when it (potentially transitively) contains a reference to
  73. /// something in a function, like an argument, basicblock, or instruction.
  74. FunctionLocalBit = 1 << 0,
  75. /// NotUniquedBit - This is set on MDNodes that are not uniqued because they
  76. /// have a null operand.
  77. NotUniquedBit = 1 << 1,
  78. /// DestroyFlag - This bit is set by destroy() so the destructor can assert
  79. /// that the node isn't being destroyed with a plain 'delete'.
  80. DestroyFlag = 1 << 2
  81. };
  82. // FunctionLocal enums.
  83. enum FunctionLocalness {
  84. FL_Unknown = -1,
  85. FL_No = 0,
  86. FL_Yes = 1
  87. };
  88. /// replaceOperand - Replace each instance of F from the operand list of this
  89. /// node with T.
  90. void replaceOperand(MDNodeOperand *Op, Value *NewVal);
  91. ~MDNode();
  92. MDNode(LLVMContext &C, ArrayRef<Value*> Vals, bool isFunctionLocal);
  93. static MDNode *getMDNode(LLVMContext &C, ArrayRef<Value*> Vals,
  94. FunctionLocalness FL, bool Insert = true);
  95. public:
  96. // Constructors and destructors.
  97. static MDNode *get(LLVMContext &Context, ArrayRef<Value*> Vals);
  98. // getWhenValsUnresolved - Construct MDNode determining function-localness
  99. // from isFunctionLocal argument, not by analyzing Vals.
  100. static MDNode *getWhenValsUnresolved(LLVMContext &Context,
  101. ArrayRef<Value*> Vals,
  102. bool isFunctionLocal);
  103. static MDNode *getIfExists(LLVMContext &Context, ArrayRef<Value*> Vals);
  104. /// getTemporary - Return a temporary MDNode, for use in constructing
  105. /// cyclic MDNode structures. A temporary MDNode is not uniqued,
  106. /// may be RAUW'd, and must be manually deleted with deleteTemporary.
  107. static MDNode *getTemporary(LLVMContext &Context, ArrayRef<Value*> Vals);
  108. /// deleteTemporary - Deallocate a node created by getTemporary. The
  109. /// node must not have any users.
  110. static void deleteTemporary(MDNode *N);
  111. /// replaceOperandWith - Replace a specific operand.
  112. void replaceOperandWith(unsigned i, Value *NewVal);
  113. /// getOperand - Return specified operand.
  114. Value *getOperand(unsigned i) const;
  115. /// getNumOperands - Return number of MDNode operands.
  116. unsigned getNumOperands() const { return NumOperands; }
  117. /// isFunctionLocal - Return whether MDNode is local to a function.
  118. bool isFunctionLocal() const {
  119. return (getSubclassDataFromValue() & FunctionLocalBit) != 0;
  120. }
  121. // getFunction - If this metadata is function-local and recursively has a
  122. // function-local operand, return the first such operand's parent function.
  123. // Otherwise, return null. getFunction() should not be used for performance-
  124. // critical code because it recursively visits all the MDNode's operands.
  125. const Function *getFunction() const;
  126. /// Profile - calculate a unique identifier for this MDNode to collapse
  127. /// duplicates
  128. void Profile(FoldingSetNodeID &ID) const;
  129. /// Methods for support type inquiry through isa, cast, and dyn_cast:
  130. static inline bool classof(const MDNode *) { return true; }
  131. static bool classof(const Value *V) {
  132. return V->getValueID() == MDNodeVal;
  133. }
  134. /// Methods for metadata merging.
  135. static MDNode *getMostGenericTBAA(MDNode *A, MDNode *B);
  136. static MDNode *getMostGenericFPMath(MDNode *A, MDNode *B);
  137. static MDNode *getMostGenericRange(MDNode *A, MDNode *B);
  138. private:
  139. // destroy - Delete this node. Only when there are no uses.
  140. void destroy();
  141. bool isNotUniqued() const {
  142. return (getSubclassDataFromValue() & NotUniquedBit) != 0;
  143. }
  144. void setIsNotUniqued();
  145. // Shadow Value::setValueSubclassData with a private forwarding method so that
  146. // any future subclasses cannot accidentally use it.
  147. void setValueSubclassData(unsigned short D) {
  148. Value::setValueSubclassData(D);
  149. }
  150. };
  151. //===----------------------------------------------------------------------===//
  152. /// NamedMDNode - a tuple of MDNodes. Despite its name, a NamedMDNode isn't
  153. /// itself an MDNode. NamedMDNodes belong to modules, have names, and contain
  154. /// lists of MDNodes.
  155. class NamedMDNode : public ilist_node<NamedMDNode> {
  156. friend class SymbolTableListTraits<NamedMDNode, Module>;
  157. friend struct ilist_traits<NamedMDNode>;
  158. friend class LLVMContextImpl;
  159. friend class Module;
  160. NamedMDNode(const NamedMDNode &) LLVM_DELETED_FUNCTION;
  161. std::string Name;
  162. Module *Parent;
  163. void *Operands; // SmallVector<TrackingVH<MDNode>, 4>
  164. void setParent(Module *M) { Parent = M; }
  165. explicit NamedMDNode(const Twine &N);
  166. public:
  167. /// eraseFromParent - Drop all references and remove the node from parent
  168. /// module.
  169. void eraseFromParent();
  170. /// dropAllReferences - Remove all uses and clear node vector.
  171. void dropAllReferences();
  172. /// ~NamedMDNode - Destroy NamedMDNode.
  173. ~NamedMDNode();
  174. /// getParent - Get the module that holds this named metadata collection.
  175. inline Module *getParent() { return Parent; }
  176. inline const Module *getParent() const { return Parent; }
  177. /// getOperand - Return specified operand.
  178. MDNode *getOperand(unsigned i) const;
  179. /// getNumOperands - Return the number of NamedMDNode operands.
  180. unsigned getNumOperands() const;
  181. /// addOperand - Add metadata operand.
  182. void addOperand(MDNode *M);
  183. /// getName - Return a constant reference to this named metadata's name.
  184. StringRef getName() const;
  185. /// print - Implement operator<< on NamedMDNode.
  186. void print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW = 0) const;
  187. /// dump() - Allow printing of NamedMDNodes from the debugger.
  188. void dump() const;
  189. };
  190. } // end llvm namespace
  191. #endif