MachineMemOperand.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. // Target hints allow target passes to annotate memory operations.
  86. MOTargetStartBit = 5,
  87. MOTargetNumBits = 3,
  88. // This is the number of bits we need to represent flags.
  89. MOMaxBits = 8
  90. };
  91. /// MachineMemOperand - Construct an MachineMemOperand object with the
  92. /// specified PtrInfo, flags, size, and base alignment.
  93. MachineMemOperand(MachinePointerInfo PtrInfo, unsigned flags, uint64_t s,
  94. unsigned base_alignment, const MDNode *TBAAInfo = 0,
  95. const MDNode *Ranges = 0);
  96. const MachinePointerInfo &getPointerInfo() const { return PtrInfo; }
  97. /// getValue - Return the base address of the memory access. This may either
  98. /// be a normal LLVM IR Value, or one of the special values used in CodeGen.
  99. /// Special values are those obtained via
  100. /// PseudoSourceValue::getFixedStack(int), PseudoSourceValue::getStack, and
  101. /// other PseudoSourceValue member functions which return objects which stand
  102. /// for frame/stack pointer relative references and other special references
  103. /// which are not representable in the high-level IR.
  104. const Value *getValue() const { return PtrInfo.V; }
  105. /// getFlags - Return the raw flags of the source value, \see MemOperandFlags.
  106. unsigned int getFlags() const { return Flags & ((1 << MOMaxBits) - 1); }
  107. /// Bitwise OR the current flags with the given flags.
  108. void setFlags(unsigned f) { Flags |= (f & ((1 << MOMaxBits) - 1)); }
  109. /// getOffset - For normal values, this is a byte offset added to the base
  110. /// address. For PseudoSourceValue::FPRel values, this is the FrameIndex
  111. /// number.
  112. int64_t getOffset() const { return PtrInfo.Offset; }
  113. unsigned getAddrSpace() const { return PtrInfo.getAddrSpace(); }
  114. /// getSize - Return the size in bytes of the memory reference.
  115. uint64_t getSize() const { return Size; }
  116. /// getAlignment - Return the minimum known alignment in bytes of the
  117. /// actual memory reference.
  118. uint64_t getAlignment() const;
  119. /// getBaseAlignment - Return the minimum known alignment in bytes of the
  120. /// base address, without the offset.
  121. uint64_t getBaseAlignment() const { return (1u << (Flags >> MOMaxBits)) >> 1; }
  122. /// getTBAAInfo - Return the TBAA tag for the memory reference.
  123. const MDNode *getTBAAInfo() const { return TBAAInfo; }
  124. /// getRanges - Return the range tag for the memory reference.
  125. const MDNode *getRanges() const { return Ranges; }
  126. bool isLoad() const { return Flags & MOLoad; }
  127. bool isStore() const { return Flags & MOStore; }
  128. bool isVolatile() const { return Flags & MOVolatile; }
  129. bool isNonTemporal() const { return Flags & MONonTemporal; }
  130. bool isInvariant() const { return Flags & MOInvariant; }
  131. /// isUnordered - Returns true if this memory operation doesn't have any
  132. /// ordering constraints other than normal aliasing. Volatile and atomic
  133. /// memory operations can't be reordered.
  134. ///
  135. /// Currently, we don't model the difference between volatile and atomic
  136. /// operations. They should retain their ordering relative to all memory
  137. /// operations.
  138. bool isUnordered() const { return !isVolatile(); }
  139. /// refineAlignment - Update this MachineMemOperand to reflect the alignment
  140. /// of MMO, if it has a greater alignment. This must only be used when the
  141. /// new alignment applies to all users of this MachineMemOperand.
  142. void refineAlignment(const MachineMemOperand *MMO);
  143. /// setValue - Change the SourceValue for this MachineMemOperand. This
  144. /// should only be used when an object is being relocated and all references
  145. /// to it are being updated.
  146. void setValue(const Value *NewSV) { PtrInfo.V = NewSV; }
  147. void setOffset(int64_t NewOffset) { PtrInfo.Offset = NewOffset; }
  148. /// Profile - Gather unique data for the object.
  149. ///
  150. void Profile(FoldingSetNodeID &ID) const;
  151. };
  152. raw_ostream &operator<<(raw_ostream &OS, const MachineMemOperand &MRO);
  153. } // End llvm namespace
  154. #endif