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.

183 lines
6.9 KiB

  1. //==- llvm/CodeGen/MachineMemOperand.h - MachineMemOperand class -*- 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 MachineMemOperand class, which is a
  11. // description of a memory reference. It is used to help track dependencies
  12. // in the backend.
  13. //
  14. //===----------------------------------------------------------------------===//
  15. #ifndef LLVM_CODEGEN_MACHINEMEMOPERAND_H
  16. #define LLVM_CODEGEN_MACHINEMEMOPERAND_H
  17. #include "llvm/Support/DataTypes.h"
  18. namespace llvm {
  19. class Value;
  20. class FoldingSetNodeID;
  21. class MDNode;
  22. class raw_ostream;
  23. /// MachinePointerInfo - This class contains a discriminated union of
  24. /// information about pointers in memory operands, relating them back to LLVM IR
  25. /// or to virtual locations (such as frame indices) that are exposed during
  26. /// codegen.
  27. struct MachinePointerInfo {
  28. /// V - This is the IR pointer value for the access, or it is null if unknown.
  29. /// If this is null, then the access is to a pointer in the default address
  30. /// space.
  31. const Value *V;
  32. /// Offset - This is an offset from the base Value*.
  33. int64_t Offset;
  34. explicit MachinePointerInfo(const Value *v = 0, int64_t offset = 0)
  35. : V(v), Offset(offset) {}
  36. MachinePointerInfo getWithOffset(int64_t O) const {
  37. if (V == 0) return MachinePointerInfo(0, 0);
  38. return MachinePointerInfo(V, Offset+O);
  39. }
  40. /// getAddrSpace - Return the LLVM IR address space number that this pointer
  41. /// points into.
  42. unsigned getAddrSpace() const;
  43. /// getConstantPool - Return a MachinePointerInfo record that refers to the
  44. /// constant pool.
  45. static MachinePointerInfo getConstantPool();
  46. /// getFixedStack - Return a MachinePointerInfo record that refers to the
  47. /// the specified FrameIndex.
  48. static MachinePointerInfo getFixedStack(int FI, int64_t offset = 0);
  49. /// getJumpTable - Return a MachinePointerInfo record that refers to a
  50. /// jump table entry.
  51. static MachinePointerInfo getJumpTable();
  52. /// getGOT - Return a MachinePointerInfo record that refers to a
  53. /// GOT entry.
  54. static MachinePointerInfo getGOT();
  55. /// getStack - stack pointer relative access.
  56. static MachinePointerInfo getStack(int64_t Offset);
  57. };
  58. //===----------------------------------------------------------------------===//
  59. /// MachineMemOperand - A description of a memory reference used in the backend.
  60. /// Instead of holding a StoreInst or LoadInst, this class holds the address
  61. /// Value of the reference along with a byte size and offset. This allows it
  62. /// to describe lowered loads and stores. Also, the special PseudoSourceValue
  63. /// objects can be used to represent loads and stores to memory locations
  64. /// that aren't explicit in the regular LLVM IR.
  65. ///
  66. class MachineMemOperand {
  67. MachinePointerInfo PtrInfo;
  68. uint64_t Size;
  69. unsigned Flags;
  70. const MDNode *TBAAInfo;
  71. const MDNode *Ranges;
  72. public:
  73. /// Flags values. These may be or'd together.
  74. enum MemOperandFlags {
  75. /// The memory access reads data.
  76. MOLoad = 1,
  77. /// The memory access writes data.
  78. MOStore = 2,
  79. /// The memory access is volatile.
  80. MOVolatile = 4,
  81. /// The memory access is non-temporal.
  82. MONonTemporal = 8,
  83. /// The memory access is invariant.
  84. MOInvariant = 16,
  85. // This is the number of bits we need to represent flags.
  86. MOMaxBits = 5
  87. };
  88. /// MachineMemOperand - Construct an MachineMemOperand object with the
  89. /// specified PtrInfo, flags, size, and base alignment.
  90. MachineMemOperand(MachinePointerInfo PtrInfo, unsigned flags, uint64_t s,
  91. unsigned base_alignment, const MDNode *TBAAInfo = 0,
  92. const MDNode *Ranges = 0);
  93. const MachinePointerInfo &getPointerInfo() const { return PtrInfo; }
  94. /// getValue - Return the base address of the memory access. This may either
  95. /// be a normal LLVM IR Value, or one of the special values used in CodeGen.
  96. /// Special values are those obtained via
  97. /// PseudoSourceValue::getFixedStack(int), PseudoSourceValue::getStack, and
  98. /// other PseudoSourceValue member functions which return objects which stand
  99. /// for frame/stack pointer relative references and other special references
  100. /// which are not representable in the high-level IR.
  101. const Value *getValue() const { return PtrInfo.V; }
  102. /// getFlags - Return the raw flags of the source value, \see MemOperandFlags.
  103. unsigned int getFlags() const { return Flags & ((1 << MOMaxBits) - 1); }
  104. /// getOffset - For normal values, this is a byte offset added to the base
  105. /// address. For PseudoSourceValue::FPRel values, this is the FrameIndex
  106. /// number.
  107. int64_t getOffset() const { return PtrInfo.Offset; }
  108. /// getSize - Return the size in bytes of the memory reference.
  109. uint64_t getSize() const { return Size; }
  110. /// getAlignment - Return the minimum known alignment in bytes of the
  111. /// actual memory reference.
  112. uint64_t getAlignment() const;
  113. /// getBaseAlignment - Return the minimum known alignment in bytes of the
  114. /// base address, without the offset.
  115. uint64_t getBaseAlignment() const { return (1u << (Flags >> MOMaxBits)) >> 1; }
  116. /// getTBAAInfo - Return the TBAA tag for the memory reference.
  117. const MDNode *getTBAAInfo() const { return TBAAInfo; }
  118. /// getRanges - Return the range tag for the memory reference.
  119. const MDNode *getRanges() const { return Ranges; }
  120. bool isLoad() const { return Flags & MOLoad; }
  121. bool isStore() const { return Flags & MOStore; }
  122. bool isVolatile() const { return Flags & MOVolatile; }
  123. bool isNonTemporal() const { return Flags & MONonTemporal; }
  124. bool isInvariant() const { return Flags & MOInvariant; }
  125. /// isUnordered - Returns true if this memory operation doesn't have any
  126. /// ordering constraints other than normal aliasing. Volatile and atomic
  127. /// memory operations can't be reordered.
  128. ///
  129. /// Currently, we don't model the difference between volatile and atomic
  130. /// operations. They should retain their ordering relative to all memory
  131. /// operations.
  132. bool isUnordered() const { return !isVolatile(); }
  133. /// refineAlignment - Update this MachineMemOperand to reflect the alignment
  134. /// of MMO, if it has a greater alignment. This must only be used when the
  135. /// new alignment applies to all users of this MachineMemOperand.
  136. void refineAlignment(const MachineMemOperand *MMO);
  137. /// setValue - Change the SourceValue for this MachineMemOperand. This
  138. /// should only be used when an object is being relocated and all references
  139. /// to it are being updated.
  140. void setValue(const Value *NewSV) { PtrInfo.V = NewSV; }
  141. void setOffset(int64_t NewOffset) { PtrInfo.Offset = NewOffset; }
  142. /// Profile - Gather unique data for the object.
  143. ///
  144. void Profile(FoldingSetNodeID &ID) const;
  145. };
  146. raw_ostream &operator<<(raw_ostream &OS, const MachineMemOperand &MRO);
  147. } // End llvm namespace
  148. #endif