1 //==- llvm/CodeGen/MachineMemOperand.h - MachineMemOperand class -*- C++ -*-==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_CODEGEN_MACHINEMEMOPERAND_H
17 #define LLVM_CODEGEN_MACHINEMEMOPERAND_H
19 #include "llvm/Support/DataTypes.h"
24 class FoldingSetNodeID;
28 /// MachinePointerInfo - This class contains a discriminated union of
29 /// information about pointers in memory operands, relating them back to LLVM IR
30 /// or to virtual locations (such as frame indices) that are exposed during
32 struct MachinePointerInfo {
33 /// V - This is the IR pointer value for the access, or it is null if unknown.
34 /// If this is null, then the access is to a pointer in the default address
38 /// Offset - This is an offset from the base Value*.
41 explicit MachinePointerInfo(const Value *v = 0, int64_t offset = 0)
42 : V(v), Offset(offset) {}
44 MachinePointerInfo getWithOffset(int64_t O) const {
45 if (V == 0) return MachinePointerInfo(0, 0);
46 return MachinePointerInfo(V, Offset+O);
49 /// getAddrSpace - Return the LLVM IR address space number that this pointer
51 unsigned getAddrSpace() const;
53 /// getConstantPool - Return a MachinePointerInfo record that refers to the
55 static MachinePointerInfo getConstantPool();
57 /// getFixedStack - Return a MachinePointerInfo record that refers to the
58 /// the specified FrameIndex.
59 static MachinePointerInfo getFixedStack(int FI, int64_t offset = 0);
61 /// getJumpTable - Return a MachinePointerInfo record that refers to a
63 static MachinePointerInfo getJumpTable();
65 /// getGOT - Return a MachinePointerInfo record that refers to a
67 static MachinePointerInfo getGOT();
69 /// getStack - stack pointer relative access.
70 static MachinePointerInfo getStack(int64_t Offset);
74 //===----------------------------------------------------------------------===//
75 /// MachineMemOperand - A description of a memory reference used in the backend.
76 /// Instead of holding a StoreInst or LoadInst, this class holds the address
77 /// Value of the reference along with a byte size and offset. This allows it
78 /// to describe lowered loads and stores. Also, the special PseudoSourceValue
79 /// objects can be used to represent loads and stores to memory locations
80 /// that aren't explicit in the regular LLVM IR.
82 class MachineMemOperand {
83 MachinePointerInfo PtrInfo;
86 const MDNode *TBAAInfo;
89 /// Flags values. These may be or'd together.
90 enum MemOperandFlags {
91 /// The memory access reads data.
93 /// The memory access writes data.
95 /// The memory access is volatile.
97 /// The memory access is non-temporal.
99 /// The memory access is invariant.
101 // This is the number of bits we need to represent flags.
105 /// MachineMemOperand - Construct an MachineMemOperand object with the
106 /// specified PtrInfo, flags, size, and base alignment.
107 MachineMemOperand(MachinePointerInfo PtrInfo, unsigned flags, uint64_t s,
108 unsigned base_alignment, const MDNode *TBAAInfo = 0);
110 const MachinePointerInfo &getPointerInfo() const { return PtrInfo; }
112 /// getValue - Return the base address of the memory access. This may either
113 /// be a normal LLVM IR Value, or one of the special values used in CodeGen.
114 /// Special values are those obtained via
115 /// PseudoSourceValue::getFixedStack(int), PseudoSourceValue::getStack, and
116 /// other PseudoSourceValue member functions which return objects which stand
117 /// for frame/stack pointer relative references and other special references
118 /// which are not representable in the high-level IR.
119 const Value *getValue() const { return PtrInfo.V; }
121 /// getFlags - Return the raw flags of the source value, \see MemOperandFlags.
122 unsigned int getFlags() const { return Flags & ((1 << MOMaxBits) - 1); }
124 /// getOffset - For normal values, this is a byte offset added to the base
125 /// address. For PseudoSourceValue::FPRel values, this is the FrameIndex
127 int64_t getOffset() const { return PtrInfo.Offset; }
129 /// getSize - Return the size in bytes of the memory reference.
130 uint64_t getSize() const { return Size; }
132 /// getAlignment - Return the minimum known alignment in bytes of the
133 /// actual memory reference.
134 uint64_t getAlignment() const;
136 /// getBaseAlignment - Return the minimum known alignment in bytes of the
137 /// base address, without the offset.
138 uint64_t getBaseAlignment() const { return (1u << (Flags >> MOMaxBits)) >> 1; }
140 /// getTBAAInfo - Return the TBAA tag for the memory reference.
141 const MDNode *getTBAAInfo() const { return TBAAInfo; }
143 bool isLoad() const { return Flags & MOLoad; }
144 bool isStore() const { return Flags & MOStore; }
145 bool isVolatile() const { return Flags & MOVolatile; }
146 bool isNonTemporal() const { return Flags & MONonTemporal; }
147 bool isInvariant() const { return Flags & MOInvariant; }
149 /// refineAlignment - Update this MachineMemOperand to reflect the alignment
150 /// of MMO, if it has a greater alignment. This must only be used when the
151 /// new alignment applies to all users of this MachineMemOperand.
152 void refineAlignment(const MachineMemOperand *MMO);
154 /// setValue - Change the SourceValue for this MachineMemOperand. This
155 /// should only be used when an object is being relocated and all references
156 /// to it are being updated.
157 void setValue(const Value *NewSV) { PtrInfo.V = NewSV; }
158 void setOffset(int64_t NewOffset) { PtrInfo.Offset = NewOffset; }
160 /// Profile - Gather unique data for the object.
162 void Profile(FoldingSetNodeID &ID) const;
165 raw_ostream &operator<<(raw_ostream &OS, const MachineMemOperand &MRO);
167 } // End llvm namespace