1//===--- ModRef.h - Memory effect modeling ----------------------*- 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// Definitions of ModRefInfo and MemoryEffects, which are used to 10// describe the memory effects of instructions. 12//===----------------------------------------------------------------------===// 14#ifndef LLVM_SUPPORT_MODREF_H 15#define LLVM_SUPPORT_MODREF_H 23/// Flags indicating whether a memory access modifies or references memory. 25/// This is no access at all, a modification, a reference, or both 26/// a modification and a reference. 28 /// The access neither references nor modifies the value stored in memory. 30 /// The access may reference the value stored in memory. 32 /// The access may modify the value stored in memory. 34 /// The access may reference and may modify the value stored in memory. 55/// Debug print ModRefInfo. 58/// The locations at which a function might access memory. 60 /// Access to memory via argument pointers. 62 /// Memory that is inaccessible via LLVM IR. 67 /// Helpers to iterate all locations in the MemoryEffectsBase class. 79staticconstexpruint32_t BitsPerLoc = 2;
80staticconstexpruint32_t LocMask = (1 << BitsPerLoc) - 1;
89 Data &= ~(LocMask << getLocationPos(Loc));
90 Data |=
static_cast<uint32_t>(MR) << getLocationPos(Loc);
94 /// Returns iterator over all supported location kinds. 100 /// Create MemoryEffectsBase that can access only the given location with the 101 /// given ModRefInfo. 104 /// Create MemoryEffectsBase that can access any location with the given 111 /// Create MemoryEffectsBase that can read and write any memory. 116 /// Create MemoryEffectsBase that cannot read or write any memory. 121 /// Create MemoryEffectsBase that can read any memory. 126 /// Create MemoryEffectsBase that can write any memory. 131 /// Create MemoryEffectsBase that can only access argument memory. 136 /// Create MemoryEffectsBase that can only access inaccessible memory. 142 /// Create MemoryEffectsBase that can only access inaccessible or argument 147 FRMB.setModRef(Location::ArgMem, MR);
148 FRMB.setModRef(Location::InaccessibleMem, MR);
152 /// Create MemoryEffectsBase from an encoded integer value (used by memory 158 /// Convert MemoryEffectsBase into an encoded integer value (used by memory 164 /// Get ModRefInfo for the given Location. 166returnModRefInfo((Data >> getLocationPos(Loc)) & LocMask);
169 /// Get new MemoryEffectsBase with modified ModRefInfo for Loc. 172 ME.setModRef(Loc, MR);
176 /// Get new MemoryEffectsBase with NoModRef on the given Loc. 183 /// Get ModRefInfo for any location. 191 /// Whether this function accesses no memory. 194 /// Whether this function only (at most) reads memory. 197 /// Whether this function only (at most) writes memory. 200 /// Whether this function only (at most) accesses argument memory. 205 /// Whether this function may access argument memory. 210 /// Whether this function only (at most) accesses inaccessible memory. 215 /// Whether this function only (at most) accesses argument and inaccessible 223 /// Intersect with other MemoryEffectsBase. 228 /// Intersect (in-place) with other MemoryEffectsBase. 234 /// Union with other MemoryEffectsBase. 239 /// Union (in-place) with other MemoryEffectsBase. 245 /// Subtract other MemoryEffectsBase. 250 /// Subtract (in-place) with other MemoryEffectsBase. 256 /// Check whether this is the same as other MemoryEffectsBase. 259 /// Check whether this is different from other MemoryEffectsBase. 263/// Summary of how a function affects memory in the program. 265/// Loads from constant globals are not considered memory accesses for this 266/// interface. Also, functions may freely modify stack space local to their 267/// invocation without having to report it through these interfaces. 270/// Debug print MemoryEffects. 276/// Components of the pointer that may be captured. 314/// Represents which components of the pointer may be captured in which 315/// location. This represents the captures(...) attribute in IR. 317/// For more information on the precise semantics see LangRef. 325 : OtherComponents(OtherComponents), RetComponents(RetComponents) {}
328 : OtherComponents(Components), RetComponents(Components) {}
330 /// Create CaptureInfo that may capture all components of the pointer. 333 /// Get components potentially captured by the return value. 336 /// Get components potentially captured through locations other than the 340 /// Get the potentially captured components of the pointer (regardless of 345return OtherComponents ==
Other.OtherComponents &&
346 RetComponents ==
Other.RetComponents;
351 /// Compute union of CaptureInfos. 354 RetComponents |
Other.RetComponents);
357 /// Compute intersection of CaptureInfos. 360 RetComponents &
Other.RetComponents);
368 /// Convert CaptureInfo into an encoded integer value (used by captures unsigned const MachineRegisterInfo * MRI
Analysis containing CSE Info
Provides some synthesis utilities to produce sequences of values.
Represents which components of the pointer may be captured in which location.
static CaptureInfo createFromIntValue(uint32_t Data)
CaptureComponents getOtherComponents() const
Get components potentially captured through locations other than the return value.
bool operator==(CaptureInfo Other) const
bool operator!=(CaptureInfo Other) const
static CaptureInfo all()
Create CaptureInfo that may capture all components of the pointer.
CaptureInfo operator&(CaptureInfo Other) const
Compute intersection of CaptureInfos.
CaptureComponents getRetComponents() const
Get components potentially captured by the return value.
CaptureInfo(CaptureComponents OtherComponents, CaptureComponents RetComponents)
CaptureInfo operator|(CaptureInfo Other) const
Compute union of CaptureInfos.
uint32_t toIntValue() const
Convert CaptureInfo into an encoded integer value (used by captures attribute).
CaptureInfo(CaptureComponents Components)
MemoryEffectsBase operator&(MemoryEffectsBase Other) const
Intersect with other MemoryEffectsBase.
static MemoryEffectsBase readOnly()
Create MemoryEffectsBase that can read any memory.
bool onlyWritesMemory() const
Whether this function only (at most) writes memory.
MemoryEffectsBase getWithoutLoc(Location Loc) const
Get new MemoryEffectsBase with NoModRef on the given Loc.
MemoryEffectsBase & operator|=(MemoryEffectsBase Other)
Union (in-place) with other MemoryEffectsBase.
MemoryEffectsBase getWithModRef(Location Loc, ModRefInfo MR) const
Get new MemoryEffectsBase with modified ModRefInfo for Loc.
bool operator!=(MemoryEffectsBase Other) const
Check whether this is different from other MemoryEffectsBase.
MemoryEffectsBase operator-(MemoryEffectsBase Other) const
Subtract other MemoryEffectsBase.
bool doesNotAccessMemory() const
Whether this function accesses no memory.
static MemoryEffectsBase argMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Create MemoryEffectsBase that can only access argument memory.
MemoryEffectsBase(ModRefInfo MR)
Create MemoryEffectsBase that can access any location with the given ModRefInfo.
bool doesAccessArgPointees() const
Whether this function may access argument memory.
static MemoryEffectsBase inaccessibleMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Create MemoryEffectsBase that can only access inaccessible memory.
bool onlyAccessesInaccessibleMem() const
Whether this function only (at most) accesses inaccessible memory.
MemoryEffectsBase(Location Loc, ModRefInfo MR)
Create MemoryEffectsBase that can access only the given location with the given ModRefInfo.
ModRefInfo getModRef(Location Loc) const
Get ModRefInfo for the given Location.
MemoryEffectsBase & operator&=(MemoryEffectsBase Other)
Intersect (in-place) with other MemoryEffectsBase.
ModRefInfo getModRef() const
Get ModRefInfo for any location.
bool onlyAccessesArgPointees() const
Whether this function only (at most) accesses argument memory.
bool onlyReadsMemory() const
Whether this function only (at most) reads memory.
static MemoryEffectsBase createFromIntValue(uint32_t Data)
Create MemoryEffectsBase from an encoded integer value (used by memory attribute).
MemoryEffectsBase & operator-=(MemoryEffectsBase Other)
Subtract (in-place) with other MemoryEffectsBase.
static MemoryEffectsBase writeOnly()
Create MemoryEffectsBase that can write any memory.
MemoryEffectsBase operator|(MemoryEffectsBase Other) const
Union with other MemoryEffectsBase.
static auto locations()
Returns iterator over all supported location kinds.
uint32_t toIntValue() const
Convert MemoryEffectsBase into an encoded integer value (used by memory attribute).
static MemoryEffectsBase inaccessibleOrArgMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Create MemoryEffectsBase that can only access inaccessible or argument memory.
static MemoryEffectsBase none()
Create MemoryEffectsBase that cannot read or write any memory.
bool operator==(MemoryEffectsBase Other) const
Check whether this is the same as other MemoryEffectsBase.
bool onlyAccessesInaccessibleOrArgMem() const
Whether this function only (at most) accesses argument and inaccessible memory.
static MemoryEffectsBase unknown()
Create MemoryEffectsBase that can read and write any memory.
This class implements an extremely fast bulk output stream that can only output to a stream.
This is an optimization pass for GlobalISel generic memory operations.
bool capturesReadProvenanceOnly(CaptureComponents CC)
bool capturesAddressIsNullOnly(CaptureComponents CC)
auto enum_seq_inclusive(EnumT Begin, EnumT End)
Iterate over an enum type from Begin to End inclusive.
bool capturesAddress(CaptureComponents CC)
constexpr force_iteration_on_noniterable_enum_t force_iteration_on_noniterable_enum
bool capturesFullProvenance(CaptureComponents CC)
bool isModSet(const ModRefInfo MRI)
MemoryEffectsBase< IRMemLocation > MemoryEffects
Summary of how a function affects memory in the program.
bool isModOrRefSet(const ModRefInfo MRI)
CaptureComponents
Components of the pointer that may be captured.
ModRefInfo
Flags indicating whether a memory access modifies or references memory.
@ Ref
The access may reference the value stored in memory.
@ ModRef
The access may reference and may modify the value stored in memory.
@ Mod
The access may modify the value stored in memory.
@ LLVM_MARK_AS_BITMASK_ENUM
@ NoModRef
The access neither references nor modifies the value stored in memory.
IRMemLocation
The locations at which a function might access memory.
@ ArgMem
Access to memory via argument pointers.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
@ InaccessibleMem
Memory that is inaccessible via LLVM IR.
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
bool isModAndRefSet(const ModRefInfo MRI)
bool capturesAnything(CaptureComponents CC)
bool capturesNothing(CaptureComponents CC)
bool isNoModRef(const ModRefInfo MRI)
bool isRefSet(const ModRefInfo MRI)