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.

158 lines
6.8 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_CONSTANT_H
  14. #define LLVM_CONSTANT_H
  15. #include "llvm/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. /// canTrap - Return true if evaluation of this constant could trap. This is
  55. /// true for things like constant expressions that could divide by zero.
  56. bool canTrap() const;
  57. /// isConstantUsed - Return true if the constant has users other than constant
  58. /// exprs and other dangling things.
  59. bool isConstantUsed() const;
  60. enum PossibleRelocationsTy {
  61. NoRelocation = 0,
  62. LocalRelocation = 1,
  63. GlobalRelocations = 2
  64. };
  65. /// getRelocationInfo - This method classifies the entry according to
  66. /// whether or not it may generate a relocation entry. This must be
  67. /// conservative, so if it might codegen to a relocatable entry, it should say
  68. /// so. The return values are:
  69. ///
  70. /// NoRelocation: This constant pool entry is guaranteed to never have a
  71. /// relocation applied to it (because it holds a simple constant like
  72. /// '4').
  73. /// LocalRelocation: This entry has relocations, but the entries are
  74. /// guaranteed to be resolvable by the static linker, so the dynamic
  75. /// linker will never see them.
  76. /// GlobalRelocations: This entry may have arbitrary relocations.
  77. ///
  78. /// FIXME: This really should not be in VMCore.
  79. PossibleRelocationsTy getRelocationInfo() const;
  80. /// getAggregateElement - For aggregates (struct/array/vector) return the
  81. /// constant that corresponds to the specified element if possible, or null if
  82. /// not. This can return null if the element index is a ConstantExpr, or if
  83. /// 'this' is a constant expr.
  84. Constant *getAggregateElement(unsigned Elt) const;
  85. Constant *getAggregateElement(Constant *Elt) const;
  86. /// destroyConstant - Called if some element of this constant is no longer
  87. /// valid. At this point only other constants may be on the use_list for this
  88. /// constant. Any constants on our Use list must also be destroy'd. The
  89. /// implementation must be sure to remove the constant from the list of
  90. /// available cached constants. Implementations should call
  91. /// destroyConstantImpl as the last thing they do, to destroy all users and
  92. /// delete this.
  93. virtual void destroyConstant() { llvm_unreachable("Not reached!"); }
  94. //// Methods for support type inquiry through isa, cast, and dyn_cast:
  95. static inline bool classof(const Constant *) { return true; }
  96. static inline bool classof(const GlobalValue *) { return true; }
  97. static inline bool classof(const Value *V) {
  98. return V->getValueID() >= ConstantFirstVal &&
  99. V->getValueID() <= ConstantLastVal;
  100. }
  101. /// replaceUsesOfWithOnConstant - This method is a special form of
  102. /// User::replaceUsesOfWith (which does not work on constants) that does work
  103. /// on constants. Basically this method goes through the trouble of building
  104. /// a new constant that is equivalent to the current one, with all uses of
  105. /// From replaced with uses of To. After this construction is completed, all
  106. /// of the users of 'this' are replaced to use the new constant, and then
  107. /// 'this' is deleted. In general, you should not call this method, instead,
  108. /// use Value::replaceAllUsesWith, which automatically dispatches to this
  109. /// method as needed.
  110. ///
  111. virtual void replaceUsesOfWithOnConstant(Value *, Value *, Use *) {
  112. // Provide a default implementation for constants (like integers) that
  113. // cannot use any other values. This cannot be called at runtime, but needs
  114. // to be here to avoid link errors.
  115. assert(getNumOperands() == 0 && "replaceUsesOfWithOnConstant must be "
  116. "implemented for all constants that have operands!");
  117. llvm_unreachable("Constants that do not have operands cannot be using "
  118. "'From'!");
  119. }
  120. static Constant *getNullValue(Type* Ty);
  121. /// @returns the value for an integer or vector of integer constant of the
  122. /// given type that has all its bits set to true.
  123. /// @brief Get the all ones value
  124. static Constant *getAllOnesValue(Type* Ty);
  125. /// getIntegerValue - Return the value for an integer or pointer constant,
  126. /// or a vector thereof, with the given scalar value.
  127. static Constant *getIntegerValue(Type* Ty, const APInt &V);
  128. /// removeDeadConstantUsers - If there are any dead constant users dangling
  129. /// off of this constant, remove them. This method is useful for clients
  130. /// that want to check to see if a global is unused, but don't want to deal
  131. /// with potentially dead constants hanging off of the globals.
  132. void removeDeadConstantUsers() const;
  133. };
  134. } // End llvm namespace
  135. #endif