LLVM  3.7.0
MachineMemOperand.h
Go to the documentation of this file.
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 
16 #ifndef LLVM_CODEGEN_MACHINEMEMOPERAND_H
17 #define LLVM_CODEGEN_MACHINEMEMOPERAND_H
18 
19 #include "llvm/ADT/PointerUnion.h"
21 #include "llvm/IR/Metadata.h"
22 #include "llvm/IR/Value.h" // PointerLikeTypeTraits<Value*>
23 #include "llvm/Support/DataTypes.h"
24 
25 namespace llvm {
26 
27 class FoldingSetNodeID;
28 class MDNode;
29 class raw_ostream;
30 class ModuleSlotTracker;
31 
32 /// MachinePointerInfo - This class contains a discriminated union of
33 /// information about pointers in memory operands, relating them back to LLVM IR
34 /// or to virtual locations (such as frame indices) that are exposed during
35 /// codegen.
37  /// V - This is the IR pointer value for the access, or it is null if unknown.
38  /// If this is null, then the access is to a pointer in the default address
39  /// space.
41 
42  /// Offset - This is an offset from the base Value*.
43  int64_t Offset;
44 
45  explicit MachinePointerInfo(const Value *v = nullptr, int64_t offset = 0)
46  : V(v), Offset(offset) {}
47 
49  int64_t offset = 0)
50  : V(v), Offset(offset) {}
51 
52  MachinePointerInfo getWithOffset(int64_t O) const {
53  if (V.isNull()) return MachinePointerInfo();
54  if (V.is<const Value*>())
55  return MachinePointerInfo(V.get<const Value*>(), Offset+O);
56  return MachinePointerInfo(V.get<const PseudoSourceValue*>(), Offset+O);
57  }
58 
59  /// getAddrSpace - Return the LLVM IR address space number that this pointer
60  /// points into.
61  unsigned getAddrSpace() const;
62 
63  /// getConstantPool - Return a MachinePointerInfo record that refers to the
64  /// constant pool.
66 
67  /// getFixedStack - Return a MachinePointerInfo record that refers to the
68  /// the specified FrameIndex.
69  static MachinePointerInfo getFixedStack(int FI, int64_t offset = 0);
70 
71  /// getJumpTable - Return a MachinePointerInfo record that refers to a
72  /// jump table entry.
74 
75  /// getGOT - Return a MachinePointerInfo record that refers to a
76  /// GOT entry.
77  static MachinePointerInfo getGOT();
78 
79  /// getStack - stack pointer relative access.
80  static MachinePointerInfo getStack(int64_t Offset);
81 };
82 
83 
84 //===----------------------------------------------------------------------===//
85 /// MachineMemOperand - A description of a memory reference used in the backend.
86 /// Instead of holding a StoreInst or LoadInst, this class holds the address
87 /// Value of the reference along with a byte size and offset. This allows it
88 /// to describe lowered loads and stores. Also, the special PseudoSourceValue
89 /// objects can be used to represent loads and stores to memory locations
90 /// that aren't explicit in the regular LLVM IR.
91 ///
93  MachinePointerInfo PtrInfo;
94  uint64_t Size;
95  unsigned Flags;
96  AAMDNodes AAInfo;
97  const MDNode *Ranges;
98 
99 public:
100  /// Flags values. These may be or'd together.
102  /// The memory access reads data.
103  MOLoad = 1,
104  /// The memory access writes data.
105  MOStore = 2,
106  /// The memory access is volatile.
108  /// The memory access is non-temporal.
110  /// The memory access is invariant.
112  // Target hints allow target passes to annotate memory operations.
115  // This is the number of bits we need to represent flags.
117  };
118 
119  /// MachineMemOperand - Construct an MachineMemOperand object with the
120  /// specified PtrInfo, flags, size, and base alignment.
121  MachineMemOperand(MachinePointerInfo PtrInfo, unsigned flags, uint64_t s,
122  unsigned base_alignment,
123  const AAMDNodes &AAInfo = AAMDNodes(),
124  const MDNode *Ranges = nullptr);
125 
126  const MachinePointerInfo &getPointerInfo() const { return PtrInfo; }
127 
128  /// getValue - Return the base address of the memory access. This may either
129  /// be a normal LLVM IR Value, or one of the special values used in CodeGen.
130  /// Special values are those obtained via
131  /// PseudoSourceValue::getFixedStack(int), PseudoSourceValue::getStack, and
132  /// other PseudoSourceValue member functions which return objects which stand
133  /// for frame/stack pointer relative references and other special references
134  /// which are not representable in the high-level IR.
135  const Value *getValue() const { return PtrInfo.V.dyn_cast<const Value*>(); }
136 
138  return PtrInfo.V.dyn_cast<const PseudoSourceValue*>();
139  }
140 
141  const void *getOpaqueValue() const { return PtrInfo.V.getOpaqueValue(); }
142 
143  /// getFlags - Return the raw flags of the source value, \see MemOperandFlags.
144  unsigned int getFlags() const { return Flags & ((1 << MOMaxBits) - 1); }
145 
146  /// Bitwise OR the current flags with the given flags.
147  void setFlags(unsigned f) { Flags |= (f & ((1 << MOMaxBits) - 1)); }
148 
149  /// getOffset - For normal values, this is a byte offset added to the base
150  /// address. For PseudoSourceValue::FPRel values, this is the FrameIndex
151  /// number.
152  int64_t getOffset() const { return PtrInfo.Offset; }
153 
154  unsigned getAddrSpace() const { return PtrInfo.getAddrSpace(); }
155 
156  /// getSize - Return the size in bytes of the memory reference.
157  uint64_t getSize() const { return Size; }
158 
159  /// getAlignment - Return the minimum known alignment in bytes of the
160  /// actual memory reference.
161  uint64_t getAlignment() const;
162 
163  /// getBaseAlignment - Return the minimum known alignment in bytes of the
164  /// base address, without the offset.
165  uint64_t getBaseAlignment() const { return (1u << (Flags >> MOMaxBits)) >> 1; }
166 
167  /// getAAInfo - Return the AA tags for the memory reference.
168  AAMDNodes getAAInfo() const { return AAInfo; }
169 
170  /// getRanges - Return the range tag for the memory reference.
171  const MDNode *getRanges() const { return Ranges; }
172 
173  bool isLoad() const { return Flags & MOLoad; }
174  bool isStore() const { return Flags & MOStore; }
175  bool isVolatile() const { return Flags & MOVolatile; }
176  bool isNonTemporal() const { return Flags & MONonTemporal; }
177  bool isInvariant() const { return Flags & MOInvariant; }
178 
179  /// isUnordered - Returns true if this memory operation doesn't have any
180  /// ordering constraints other than normal aliasing. Volatile and atomic
181  /// memory operations can't be reordered.
182  ///
183  /// Currently, we don't model the difference between volatile and atomic
184  /// operations. They should retain their ordering relative to all memory
185  /// operations.
186  bool isUnordered() const { return !isVolatile(); }
187 
188  /// refineAlignment - Update this MachineMemOperand to reflect the alignment
189  /// of MMO, if it has a greater alignment. This must only be used when the
190  /// new alignment applies to all users of this MachineMemOperand.
191  void refineAlignment(const MachineMemOperand *MMO);
192 
193  /// setValue - Change the SourceValue for this MachineMemOperand. This
194  /// should only be used when an object is being relocated and all references
195  /// to it are being updated.
196  void setValue(const Value *NewSV) { PtrInfo.V = NewSV; }
197  void setValue(const PseudoSourceValue *NewSV) { PtrInfo.V = NewSV; }
198  void setOffset(int64_t NewOffset) { PtrInfo.Offset = NewOffset; }
199 
200  /// Profile - Gather unique data for the object.
201  ///
202  void Profile(FoldingSetNodeID &ID) const;
203 
204  /// Support for operator<<.
205  /// @{
206  void print(raw_ostream &OS) const;
207  void print(raw_ostream &OS, ModuleSlotTracker &MST) const;
208  /// @}
209 
210  friend bool operator==(const MachineMemOperand &LHS,
211  const MachineMemOperand &RHS) {
212  return LHS.getValue() == RHS.getValue() &&
213  LHS.getPseudoValue() == RHS.getPseudoValue() &&
214  LHS.getSize() == RHS.getSize() &&
215  LHS.getOffset() == RHS.getOffset() &&
216  LHS.getFlags() == RHS.getFlags() &&
217  LHS.getAAInfo() == RHS.getAAInfo() &&
218  LHS.getRanges() == RHS.getRanges() &&
219  LHS.getAlignment() == RHS.getAlignment() &&
220  LHS.getAddrSpace() == RHS.getAddrSpace();
221  }
222 
223  friend bool operator!=(const MachineMemOperand &LHS,
224  const MachineMemOperand &RHS) {
225  return !(LHS == RHS);
226  }
227 };
228 
230  MRO.print(OS);
231  return OS;
232 }
233 
234 } // End llvm namespace
235 
236 #endif
The memory access reads data.
The memory access writes data.
static MachinePointerInfo getJumpTable()
getJumpTable - Return a MachinePointerInfo record that refers to a jump table entry.
T dyn_cast() const
dyn_cast<T>() - If the current value is of the specified pointer type, return it, otherwise return nu...
Definition: PointerUnion.h:138
This file contains the declarations for metadata subclasses.
Metadata node.
Definition: Metadata.h:740
Manage lifetime of a slot tracker for printing IR.
static MachinePointerInfo getConstantPool()
getConstantPool - Return a MachinePointerInfo record that refers to the constant pool.
const MachinePointerInfo & getPointerInfo() const
static MachinePointerInfo getFixedStack(int FI, int64_t offset=0)
getFixedStack - Return a MachinePointerInfo record that refers to the the specified FrameIndex...
void * getOpaqueValue() const
Definition: PointerUnion.h:178
MachineMemOperand - A description of a memory reference used in the backend.
MachinePointerInfo(const PseudoSourceValue *v, int64_t offset=0)
MachinePointerInfo getWithOffset(int64_t O) const
friend bool operator!=(const MachineMemOperand &LHS, const MachineMemOperand &RHS)
The memory access is volatile.
void setFlags(unsigned f)
Bitwise OR the current flags with the given flags.
uint64_t getAlignment() const
getAlignment - Return the minimum known alignment in bytes of the actual memory reference.
The memory access is non-temporal.
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:297
unsigned int getFlags() const
getFlags - Return the raw flags of the source value,
AAMDNodes getAAInfo() const
getAAInfo - Return the AA tags for the memory reference.
PointerUnion< const Value *, const PseudoSourceValue * > V
V - This is the IR pointer value for the access, or it is null if unknown.
int64_t Offset
Offset - This is an offset from the base Value*.
void Profile(FoldingSetNodeID &ID) const
Profile - Gather unique data for the object.
void setOffset(int64_t NewOffset)
const PseudoSourceValue * getPseudoValue() const
MachinePointerInfo - This class contains a discriminated union of information about pointers in memor...
bool isNull() const
isNull - Return true if the pointer held in the union is null, regardless of which type it is...
Definition: PointerUnion.h:109
The memory access is invariant.
void refineAlignment(const MachineMemOperand *MMO)
refineAlignment - Update this MachineMemOperand to reflect the alignment of MMO, if it has a greater ...
const void * getOpaqueValue() const
void setValue(const Value *NewSV)
setValue - Change the SourceValue for this MachineMemOperand.
T get() const
get<T>() - Return the value of the specified pointer type.
Definition: PointerUnion.h:130
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Definition: Metadata.h:548
unsigned getAddrSpace() const
getAddrSpace - Return the LLVM IR address space number that this pointer points into.
MemOperandFlags
Flags values. These may be or'd together.
static MachinePointerInfo getStack(int64_t Offset)
getStack - stack pointer relative access.
MachineMemOperand(MachinePointerInfo PtrInfo, unsigned flags, uint64_t s, unsigned base_alignment, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr)
MachineMemOperand - Construct an MachineMemOperand object with the specified PtrInfo, flags, size, and base alignment.
const Value * getValue() const
getValue - Return the base address of the memory access.
PseudoSourceValue - Special value supplied for machine level alias analysis.
void print(raw_ostream &OS) const
Support for operator<<.
friend bool operator==(const MachineMemOperand &LHS, const MachineMemOperand &RHS)
static MachinePointerInfo getGOT()
getGOT - Return a MachinePointerInfo record that refers to a GOT entry.
bool isUnordered() const
isUnordered - Returns true if this memory operation doesn't have any ordering constraints other than ...
unsigned getAddrSpace() const
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
Definition: APInt.h:1738
void setValue(const PseudoSourceValue *NewSV)
MachinePointerInfo(const Value *v=nullptr, int64_t offset=0)
const MDNode * getRanges() const
getRanges - Return the range tag for the memory reference.
LLVM Value Representation.
Definition: Value.h:69
int64_t getOffset() const
getOffset - For normal values, this is a byte offset added to the base address.
uint64_t getSize() const
getSize - Return the size in bytes of the memory reference.
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:38
int is() const
is<T>() return true if the Union currently holds the type matching T.
Definition: PointerUnion.h:118
uint64_t getBaseAlignment() const
getBaseAlignment - Return the minimum known alignment in bytes of the base address, without the offset.