1//==- llvm/CodeGen/MachineMemOperand.h - MachineMemOperand class -*- C++ -*-==//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//===----------------------------------------------------------------------===//
9// This file contains the declaration of the MachineMemOperand class, which is a
10// description of a memory reference. It is used to help track dependencies
13//===----------------------------------------------------------------------===//
15#ifndef LLVM_CODEGEN_MACHINEMEMOPERAND_H
16#define LLVM_CODEGEN_MACHINEMEMOPERAND_H
39/// This class contains a discriminated union of information about pointers in
40/// memory operands, relating them back to LLVM IR or to virtual locations (such
41/// as frame indices) that are exposed during codegen.
43 /// This is the IR pointer value for the access, or it is null if unknown.
46 /// Offset - This is an offset from the base Value*.
76 AddrSpace = ValPtr->getType()->getPointerAddressSpace();
91 /// Return true if memory region [V, V+Offset+Size) is known to be
96 /// Return the LLVM IR address space number that this pointer points into.
99 /// Return a MachinePointerInfo record that refers to the constant pool.
102 /// Return a MachinePointerInfo record that refers to the specified
107 /// Return a MachinePointerInfo record that refers to a jump table entry.
110 /// Return a MachinePointerInfo record that refers to a GOT entry.
113 /// Stack pointer relative access.
117 /// Stack memory without other information.
122//===----------------------------------------------------------------------===//
123/// A description of a memory reference used in the backend.
124/// Instead of holding a StoreInst or LoadInst, this class holds the address
125/// Value of the reference along with a byte size and offset. This allows it
126/// to describe lowered loads and stores. Also, the special PseudoSourceValue
127/// objects can be used to represent loads and stores to memory locations
128/// that aren't explicit in the regular LLVM IR.
132 /// Flags values. These may be or'd together.
136 /// The memory access reads data.
138 /// The memory access writes data.
140 /// The memory access is volatile.
142 /// The memory access is non-temporal.
144 /// The memory access is dereferenceable (i.e., doesn't trap).
146 /// The memory access always returns the same value (or traps).
149 // Reserved for use by target-specific passes.
150 // Targets may override getSerializableMachineMemOperandTargetFlags() to
151 // enable MIR serialization/parsing of these flags. If more of these flags
152 // are added, the MIR printing/parsing code will need to be updated as well.
162 /// Atomic information for this memory operation.
163 struct MachineAtomicInfo {
164 /// Synchronization scope ID for this memory operation.
165 unsigned SSID : 8;
// SyncScope::ID
166 /// Atomic ordering requirements for this memory operation. For cmpxchg
167 /// atomic operations, atomic ordering requirements when store occurs.
168 unsigned Ordering : 4;
// enum AtomicOrdering
169 /// For cmpxchg atomic operations, atomic ordering requirements when store
171 unsigned FailureOrdering : 4;
// enum AtomicOrdering
174 MachinePointerInfo PtrInfo;
176 /// Track the memory type of the access. An access size which is unknown or
177 /// too large to be represented by LLT should use the invalid LLT.
182 MachineAtomicInfo AtomicInfo;
184 const MDNode *Ranges;
187 /// Construct a MachineMemOperand object with the specified PtrInfo, flags,
188 /// size, and base alignment. For atomic operations the synchronization scope
189 /// and atomic ordering requirements must also be specified. For cmpxchg
190 /// atomic operations the atomic ordering requirements when store does not
191 /// occur must also be specified.
194 Align a,
const AAMDNodes &AAInfo = AAMDNodes(),
195 const MDNode *Ranges =
nullptr,
201 const AAMDNodes &AAInfo = AAMDNodes(),
202 const MDNode *Ranges =
nullptr,
209 /// Return the base address of the memory access. This may either be a normal
210 /// LLVM IR Value, or one of the special values used in CodeGen.
211 /// Special values are those obtained via
212 /// PseudoSourceValue::getFixedStack(int), PseudoSourceValue::getStack, and
213 /// other PseudoSourceValue member functions which return objects which stand
214 /// for frame/stack pointer relative references and other special references
215 /// which are not representable in the high-level IR.
226 /// Return the raw flags of the source value, \see Flags.
229 /// Bitwise OR the current flags with the given flags.
232 /// For normal values, this is a byte offset added to the base address.
233 /// For PseudoSourceValue::FPRel values, this is the FrameIndex number.
238 /// Return the memory type of the memory reference. This should only be relied
239 /// on for GlobalISel G_* operation legalization.
242 /// Return the size in bytes of the memory reference.
244 return MemoryType.isValid()
249 /// Return the size in bits of the memory reference.
251 return MemoryType.isValid()
260 /// Return the minimum known alignment in bytes of the actual memory
264 /// Return the minimum known alignment in bytes of the base address, without
268 /// Return the AA tags for the memory reference.
271 /// Return the range tag for the memory reference.
274 /// Returns the synchronization scope ID for this memory operation.
279 /// Return the atomic ordering requirements for this memory operation. For
280 /// cmpxchg atomic operations, return the atomic ordering requirements when
286 /// For cmpxchg atomic operations, return the atomic ordering requirements
287 /// when store does not occur.
292 /// Return a single atomic ordering that is at least as strong as both the
293 /// success and failure orderings for an atomic operation. (For operations
294 /// other than cmpxchg, this is equivalent to getSuccessOrdering().)
306 /// Returns true if this operation has an atomic ordering requirement of
307 /// unordered or higher, false otherwise.
312 /// Returns true if this memory operation doesn't have any ordering
313 /// constraints other than normal aliasing. Volatile and (ordered) atomic
314 /// memory operations can't be reordered.
321 /// Update this MachineMemOperand to reflect the alignment of MMO, if it has a
322 /// greater alignment. This must only be used when the new alignment applies
323 /// to all users of this MachineMemOperand.
326 /// Change the SourceValue for this MachineMemOperand. This should only be
327 /// used when an object is being relocated and all references to it are being
331 void setOffset(int64_t NewOffset) { PtrInfo.Offset = NewOffset; }
333 /// Reset the tracked memory type.
338 /// Unset the tracked range metadata.
341 /// Support for operator<<.
351 return LHS.getValue() ==
RHS.getValue() &&
352 LHS.getPseudoValue() ==
RHS.getPseudoValue() &&
353 LHS.getSize() ==
RHS.getSize() &&
354 LHS.getOffset() ==
RHS.getOffset() &&
355 LHS.getFlags() ==
RHS.getFlags() &&
356 LHS.getAAInfo() ==
RHS.getAAInfo() &&
357 LHS.getRanges() ==
RHS.getRanges() &&
358 LHS.getAlign() ==
RHS.getAlign() &&
359 LHS.getAddrSpace() ==
RHS.getAddrSpace();
368}
// End llvm namespace
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Atomic ordering constants.
const HexagonInstrInfo * TII
Implement a low-level type suitable for MachineInstr level instruction selection.
This file provides utility analysis objects describing memory locations.
This file defines the PointerUnion class, which is a discriminated union of pointer types.
A parsed version of the target data layout string in and methods for querying it.
This is an important class for using LLVM in a threaded context.
static LocationSize precise(uint64_t Value)
static constexpr LocationSize beforeOrAfterPointer()
Any location before or after the base pointer (but still within the underlying object).
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
A description of a memory reference used in the backend.
void setType(LLT NewTy)
Reset the tracked memory type.
LocationSize getSize() const
Return the size in bytes of the memory reference.
AtomicOrdering getFailureOrdering() const
For cmpxchg atomic operations, return the atomic ordering requirements when store does not occur.
const PseudoSourceValue * getPseudoValue() const
LLT getMemoryType() const
Return the memory type of the memory reference.
unsigned getAddrSpace() const
void clearRanges()
Unset the tracked range metadata.
LLVM_ABI void print(raw_ostream &OS, ModuleSlotTracker &MST, SmallVectorImpl< StringRef > &SSNs, const LLVMContext &Context, const MachineFrameInfo *MFI, const TargetInstrInfo *TII) const
Support for operator<<.
bool isNonTemporal() const
bool isUnordered() const
Returns true if this memory operation doesn't have any ordering constraints other than normal aliasin...
const MDNode * getRanges() const
Return the range tag for the memory reference.
void setValue(const Value *NewSV)
Change the SourceValue for this MachineMemOperand.
bool isAtomic() const
Returns true if this operation has an atomic ordering requirement of unordered or higher,...
LLVM_ABI void refineAlignment(const MachineMemOperand *MMO)
Update this MachineMemOperand to reflect the alignment of MMO, if it has a greater alignment.
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID for this memory operation.
const void * getOpaqueValue() const
friend bool operator!=(const MachineMemOperand &LHS, const MachineMemOperand &RHS)
LLVM_ABI MachineMemOperand(MachinePointerInfo PtrInfo, Flags flags, LocationSize TS, Align a, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
Construct a MachineMemOperand object with the specified PtrInfo, flags, size, and base alignment.
AtomicOrdering getMergedOrdering() const
Return a single atomic ordering that is at least as strong as both the success and failure orderings ...
void setOffset(int64_t NewOffset)
Flags
Flags values. These may be or'd together.
@ MOVolatile
The memory access is volatile.
@ MODereferenceable
The memory access is dereferenceable (i.e., doesn't trap).
@ MOLoad
The memory access reads data.
@ MONonTemporal
The memory access is non-temporal.
@ MOInvariant
The memory access always returns the same value (or traps).
@ MOStore
The memory access writes data.
AtomicOrdering getSuccessOrdering() const
Return the atomic ordering requirements for this memory operation.
void setFlags(Flags f)
Bitwise OR the current flags with the given flags.
const MachinePointerInfo & getPointerInfo() const
Flags getFlags() const
Return the raw flags of the source value,.
LLVM_ABI Align getAlign() const
Return the minimum known alignment in bytes of the actual memory reference.
LocationSize getSizeInBits() const
Return the size in bits of the memory reference.
bool isDereferenceable() const
friend bool operator==(const MachineMemOperand &LHS, const MachineMemOperand &RHS)
AAMDNodes getAAInfo() const
Return the AA tags for the memory reference.
void setValue(const PseudoSourceValue *NewSV)
const Value * getValue() const
Return the base address of the memory access.
Align getBaseAlign() const
Return the minimum known alignment in bytes of the base address, without the offset.
int64_t getOffset() const
For normal values, this is a byte offset added to the base address.
Manage lifetime of a slot tracker for printing IR.
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
Special value supplied for machine level alias analysis.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
TargetInstrInfo - Interface to description of machine instruction set.
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
@ System
Synchronized with respect to all concurrently executing threads.
This is an optimization pass for GlobalISel generic memory operations.
unsigned getPointerAddressSpace(const Type *T)
auto dyn_cast_if_present(const Y &Val)
dyn_cast_if_present<X> - Functionally identical to dyn_cast, except that a null (or none in the case ...
AtomicOrdering getMergedAtomicOrdering(AtomicOrdering AO, AtomicOrdering Other)
Return a single atomic ordering that is at least as strong as both the AO and Other orderings for an ...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
AtomicOrdering
Atomic ordering for LLVM's memory model.
@ LLVM_MARK_AS_BITMASK_ENUM
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
This struct is a compact representation of a valid (non-zero power of two) alignment.
This class contains a discriminated union of information about pointers in memory operands,...
static LLVM_ABI MachinePointerInfo getJumpTable(MachineFunction &MF)
Return a MachinePointerInfo record that refers to a jump table entry.
LLVM_ABI bool isDereferenceable(unsigned Size, LLVMContext &C, const DataLayout &DL) const
Return true if memory region [V, V+Offset+Size) is known to be dereferenceable.
MachinePointerInfo(const PseudoSourceValue *v, int64_t offset=0, uint8_t ID=0)
LLVM_ABI unsigned getAddrSpace() const
Return the LLVM IR address space number that this pointer points into.
static LLVM_ABI MachinePointerInfo getStack(MachineFunction &MF, int64_t Offset, uint8_t ID=0)
Stack pointer relative access.
MachinePointerInfo(unsigned AddressSpace=0, int64_t offset=0)
int64_t Offset
Offset - This is an offset from the base Value*.
MachinePointerInfo(PointerUnion< const Value *, const PseudoSourceValue * > v, int64_t offset=0, uint8_t ID=0)
PointerUnion< const Value *, const PseudoSourceValue * > V
This is the IR pointer value for the access, or it is null if unknown.
static LLVM_ABI MachinePointerInfo getConstantPool(MachineFunction &MF)
Return a MachinePointerInfo record that refers to the constant pool.
MachinePointerInfo getWithOffset(int64_t O) const
static LLVM_ABI MachinePointerInfo getUnknownStack(MachineFunction &MF)
Stack memory without other information.
static LLVM_ABI MachinePointerInfo getGOT(MachineFunction &MF)
Return a MachinePointerInfo record that refers to a GOT entry.
MachinePointerInfo(const Value *v, int64_t offset=0, uint8_t ID=0)
static LLVM_ABI MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.