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.

174 lines
6.0 KiB

  1. //===-- CodeGen/MachineConstantPool.h - Abstract Constant Pool --*- 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 declares the MachineConstantPool class which is an abstract
  12. /// constant pool to keep track of constants referenced by a function.
  13. //
  14. //===----------------------------------------------------------------------===//
  15. #ifndef LLVM_CODEGEN_MACHINECONSTANTPOOL_H
  16. #define LLVM_CODEGEN_MACHINECONSTANTPOOL_H
  17. #include "llvm/ADT/DenseSet.h"
  18. #include <cassert>
  19. #include <climits>
  20. #include <vector>
  21. namespace llvm {
  22. class Constant;
  23. class FoldingSetNodeID;
  24. class DataLayout;
  25. class TargetMachine;
  26. class Type;
  27. class MachineConstantPool;
  28. class raw_ostream;
  29. /// Abstract base class for all machine specific constantpool value subclasses.
  30. ///
  31. class MachineConstantPoolValue {
  32. virtual void anchor();
  33. Type *Ty;
  34. public:
  35. explicit MachineConstantPoolValue(Type *ty) : Ty(ty) {}
  36. virtual ~MachineConstantPoolValue() {}
  37. /// getType - get type of this MachineConstantPoolValue.
  38. ///
  39. Type *getType() const { return Ty; }
  40. /// getRelocationInfo - This method classifies the entry according to
  41. /// whether or not it may generate a relocation entry. This must be
  42. /// conservative, so if it might codegen to a relocatable entry, it should say
  43. /// so. The return values are the same as Constant::getRelocationInfo().
  44. virtual unsigned getRelocationInfo() const = 0;
  45. virtual int getExistingMachineCPValue(MachineConstantPool *CP,
  46. unsigned Alignment) = 0;
  47. virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID) = 0;
  48. /// print - Implement operator<<
  49. virtual void print(raw_ostream &O) const = 0;
  50. };
  51. inline raw_ostream &operator<<(raw_ostream &OS,
  52. const MachineConstantPoolValue &V) {
  53. V.print(OS);
  54. return OS;
  55. }
  56. /// This class is a data container for one entry in a MachineConstantPool.
  57. /// It contains a pointer to the value and an offset from the start of
  58. /// the constant pool.
  59. /// @brief An entry in a MachineConstantPool
  60. class MachineConstantPoolEntry {
  61. public:
  62. /// The constant itself.
  63. union {
  64. const Constant *ConstVal;
  65. MachineConstantPoolValue *MachineCPVal;
  66. } Val;
  67. /// The required alignment for this entry. The top bit is set when Val is
  68. /// a target specific MachineConstantPoolValue.
  69. unsigned Alignment;
  70. MachineConstantPoolEntry(const Constant *V, unsigned A)
  71. : Alignment(A) {
  72. Val.ConstVal = V;
  73. }
  74. MachineConstantPoolEntry(MachineConstantPoolValue *V, unsigned A)
  75. : Alignment(A) {
  76. Val.MachineCPVal = V;
  77. Alignment |= 1U << (sizeof(unsigned)*CHAR_BIT-1);
  78. }
  79. /// isMachineConstantPoolEntry - Return true if the MachineConstantPoolEntry
  80. /// is indeed a target specific constantpool entry, not a wrapper over a
  81. /// Constant.
  82. bool isMachineConstantPoolEntry() const {
  83. return (int)Alignment < 0;
  84. }
  85. int getAlignment() const {
  86. return Alignment & ~(1 << (sizeof(unsigned)*CHAR_BIT-1));
  87. }
  88. Type *getType() const;
  89. /// getRelocationInfo - This method classifies the entry according to
  90. /// whether or not it may generate a relocation entry. This must be
  91. /// conservative, so if it might codegen to a relocatable entry, it should say
  92. /// so. The return values are:
  93. ///
  94. /// 0: This constant pool entry is guaranteed to never have a relocation
  95. /// applied to it (because it holds a simple constant like '4').
  96. /// 1: This entry has relocations, but the entries are guaranteed to be
  97. /// resolvable by the static linker, so the dynamic linker will never see
  98. /// them.
  99. /// 2: This entry may have arbitrary relocations.
  100. unsigned getRelocationInfo() const;
  101. };
  102. /// The MachineConstantPool class keeps track of constants referenced by a
  103. /// function which must be spilled to memory. This is used for constants which
  104. /// are unable to be used directly as operands to instructions, which typically
  105. /// include floating point and large integer constants.
  106. ///
  107. /// Instructions reference the address of these constant pool constants through
  108. /// the use of MO_ConstantPoolIndex values. When emitting assembly or machine
  109. /// code, these virtual address references are converted to refer to the
  110. /// address of the function constant pool values.
  111. /// @brief The machine constant pool.
  112. class MachineConstantPool {
  113. const DataLayout *TD; ///< The machine's DataLayout.
  114. unsigned PoolAlignment; ///< The alignment for the pool.
  115. std::vector<MachineConstantPoolEntry> Constants; ///< The pool of constants.
  116. /// MachineConstantPoolValues that use an existing MachineConstantPoolEntry.
  117. DenseSet<MachineConstantPoolValue*> MachineCPVsSharingEntries;
  118. public:
  119. /// @brief The only constructor.
  120. explicit MachineConstantPool(const DataLayout *td)
  121. : TD(td), PoolAlignment(1) {}
  122. ~MachineConstantPool();
  123. /// getConstantPoolAlignment - Return the alignment required by
  124. /// the whole constant pool, of which the first element must be aligned.
  125. unsigned getConstantPoolAlignment() const { return PoolAlignment; }
  126. /// getConstantPoolIndex - Create a new entry in the constant pool or return
  127. /// an existing one. User must specify the minimum required alignment for
  128. /// the object.
  129. unsigned getConstantPoolIndex(const Constant *C, unsigned Alignment);
  130. unsigned getConstantPoolIndex(MachineConstantPoolValue *V,unsigned Alignment);
  131. /// isEmpty - Return true if this constant pool contains no constants.
  132. bool isEmpty() const { return Constants.empty(); }
  133. const std::vector<MachineConstantPoolEntry> &getConstants() const {
  134. return Constants;
  135. }
  136. /// print - Used by the MachineFunction printer to print information about
  137. /// constant pool objects. Implemented in MachineFunction.cpp
  138. ///
  139. void print(raw_ostream &OS) const;
  140. /// dump - Call print(cerr) to be called from the debugger.
  141. void dump() const;
  142. };
  143. } // End llvm namespace
  144. #endif