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.

170 lines
7.2 KiB

  1. //===-- llvm/Constant.h - Constant class definition -------------*- 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. // This file contains the declaration of the Constant class.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_IR_CONSTANT_H
  14. #define LLVM_IR_CONSTANT_H
  15. #include "llvm/IR/User.h"
  16. namespace llvm {
  17. class APInt;
  18. template<typename T> class SmallVectorImpl;
  19. /// This is an important base class in LLVM. It provides the common facilities
  20. /// of all constant values in an LLVM program. A constant is a value that is
  21. /// immutable at runtime. Functions are constants because their address is
  22. /// immutable. Same with global variables.
  23. ///
  24. /// All constants share the capabilities provided in this class. All constants
  25. /// can have a null value. They can have an operand list. Constants can be
  26. /// simple (integer and floating point values), complex (arrays and structures),
  27. /// or expression based (computations yielding a constant value composed of
  28. /// only certain operators and other constant values).
  29. ///
  30. /// Note that Constants are immutable (once created they never change)
  31. /// and are fully shared by structural equivalence. This means that two
  32. /// structurally equivalent constants will always have the same address.
  33. /// Constants are created on demand as needed and never deleted: thus clients
  34. /// don't have to worry about the lifetime of the objects.
  35. /// @brief LLVM Constant Representation
  36. class Constant : public User {
  37. void operator=(const Constant &) LLVM_DELETED_FUNCTION;
  38. Constant(const Constant &) LLVM_DELETED_FUNCTION;
  39. virtual void anchor();
  40. protected:
  41. Constant(Type *ty, ValueTy vty, Use *Ops, unsigned NumOps)
  42. : User(ty, vty, Ops, NumOps) {}
  43. void destroyConstantImpl();
  44. public:
  45. /// isNullValue - Return true if this is the value that would be returned by
  46. /// getNullValue.
  47. bool isNullValue() const;
  48. /// isAllOnesValue - Return true if this is the value that would be returned by
  49. /// getAllOnesValue.
  50. bool isAllOnesValue() const;
  51. /// isNegativeZeroValue - Return true if the value is what would be returned
  52. /// by getZeroValueForNegation.
  53. bool isNegativeZeroValue() const;
  54. /// Return true if the value is negative zero or null value.
  55. bool isZeroValue() const;
  56. /// canTrap - Return true if evaluation of this constant could trap. This is
  57. /// true for things like constant expressions that could divide by zero.
  58. bool canTrap() const;
  59. /// isThreadDependent - Return true if the value can vary between threads.
  60. bool isThreadDependent() const;
  61. /// isConstantUsed - Return true if the constant has users other than constant
  62. /// exprs and other dangling things.
  63. bool isConstantUsed() const;
  64. enum PossibleRelocationsTy {
  65. NoRelocation = 0,
  66. LocalRelocation = 1,
  67. GlobalRelocations = 2
  68. };
  69. /// getRelocationInfo - This method classifies the entry according to
  70. /// whether or not it may generate a relocation entry. This must be
  71. /// conservative, so if it might codegen to a relocatable entry, it should say
  72. /// so. The return values are:
  73. ///
  74. /// NoRelocation: This constant pool entry is guaranteed to never have a
  75. /// relocation applied to it (because it holds a simple constant like
  76. /// '4').
  77. /// LocalRelocation: This entry has relocations, but the entries are
  78. /// guaranteed to be resolvable by the static linker, so the dynamic
  79. /// linker will never see them.
  80. /// GlobalRelocations: This entry may have arbitrary relocations.
  81. ///
  82. /// FIXME: This really should not be in VMCore.
  83. PossibleRelocationsTy getRelocationInfo() const;
  84. /// getAggregateElement - For aggregates (struct/array/vector) return the
  85. /// constant that corresponds to the specified element if possible, or null if
  86. /// not. This can return null if the element index is a ConstantExpr, or if
  87. /// 'this' is a constant expr.
  88. Constant *getAggregateElement(unsigned Elt) const;
  89. Constant *getAggregateElement(Constant *Elt) const;
  90. /// getSplatValue - If this is a splat vector constant, meaning that all of
  91. /// the elements have the same value, return that value. Otherwise return 0.
  92. Constant *getSplatValue() const;
  93. /// If C is a constant integer then return its value, otherwise C must be a
  94. /// vector of constant integers, all equal, and the common value is returned.
  95. const APInt &getUniqueInteger() const;
  96. /// destroyConstant - Called if some element of this constant is no longer
  97. /// valid. At this point only other constants may be on the use_list for this
  98. /// constant. Any constants on our Use list must also be destroy'd. The
  99. /// implementation must be sure to remove the constant from the list of
  100. /// available cached constants. Implementations should call
  101. /// destroyConstantImpl as the last thing they do, to destroy all users and
  102. /// delete this.
  103. virtual void destroyConstant() { llvm_unreachable("Not reached!"); }
  104. //// Methods for support type inquiry through isa, cast, and dyn_cast:
  105. static inline bool classof(const Value *V) {
  106. return V->getValueID() >= ConstantFirstVal &&
  107. V->getValueID() <= ConstantLastVal;
  108. }
  109. /// replaceUsesOfWithOnConstant - This method is a special form of
  110. /// User::replaceUsesOfWith (which does not work on constants) that does work
  111. /// on constants. Basically this method goes through the trouble of building
  112. /// a new constant that is equivalent to the current one, with all uses of
  113. /// From replaced with uses of To. After this construction is completed, all
  114. /// of the users of 'this' are replaced to use the new constant, and then
  115. /// 'this' is deleted. In general, you should not call this method, instead,
  116. /// use Value::replaceAllUsesWith, which automatically dispatches to this
  117. /// method as needed.
  118. ///
  119. virtual void replaceUsesOfWithOnConstant(Value *, Value *, Use *) {
  120. // Provide a default implementation for constants (like integers) that
  121. // cannot use any other values. This cannot be called at runtime, but needs
  122. // to be here to avoid link errors.
  123. assert(getNumOperands() == 0 && "replaceUsesOfWithOnConstant must be "
  124. "implemented for all constants that have operands!");
  125. llvm_unreachable("Constants that do not have operands cannot be using "
  126. "'From'!");
  127. }
  128. static Constant *getNullValue(Type* Ty);
  129. /// @returns the value for an integer or vector of integer constant of the
  130. /// given type that has all its bits set to true.
  131. /// @brief Get the all ones value
  132. static Constant *getAllOnesValue(Type* Ty);
  133. /// getIntegerValue - Return the value for an integer or pointer constant,
  134. /// or a vector thereof, with the given scalar value.
  135. static Constant *getIntegerValue(Type* Ty, const APInt &V);
  136. /// removeDeadConstantUsers - If there are any dead constant users dangling
  137. /// off of this constant, remove them. This method is useful for clients
  138. /// that want to check to see if a global is unused, but don't want to deal
  139. /// with potentially dead constants hanging off of the globals.
  140. void removeDeadConstantUsers() const;
  141. };
  142. } // End llvm namespace
  143. #endif