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.

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