[llvm] 2c78a9e - [AST] Use ModRefInfo to represent access kind (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 17 09:07:35 PDT 2023
Author: Nikita Popov
Date: 2023-03-17T17:07:27+01:00
New Revision: 2c78a9e65ccfe36d213a409592bebdd3ed8ba771
URL: https://github.com/llvm/llvm-project/commit/2c78a9e65ccfe36d213a409592bebdd3ed8ba771
DIFF: https://github.com/llvm/llvm-project/commit/2c78a9e65ccfe36d213a409592bebdd3ed8ba771.diff
LOG: [AST] Use ModRefInfo to represent access kind (NFC)
AST was using a custom enum with exactly the same semantics. Use
the standard one instead.
Added:
Modified:
llvm/include/llvm/Analysis/AliasSetTracker.h
llvm/lib/Analysis/AliasSetTracker.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/AliasSetTracker.h b/llvm/include/llvm/Analysis/AliasSetTracker.h
index e485e1ff2f4c9..6fdca459e9c96 100644
--- a/llvm/include/llvm/Analysis/AliasSetTracker.h
+++ b/llvm/include/llvm/Analysis/AliasSetTracker.h
@@ -26,6 +26,7 @@
#include "llvm/IR/Instruction.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/ValueHandle.h"
+#include "llvm/Support/ModRef.h"
#include <cassert>
#include <cstddef>
#include <iterator>
@@ -157,15 +158,9 @@ class AliasSet : public ilist_node<AliasSet> {
///
/// We keep track of whether this alias set merely refers to the locations of
/// memory (and not any particular access), whether it modifies or references
- /// the memory, or whether it does both. The lattice goes from "NoAccess" to
- /// either RefAccess or ModAccess, then to ModRefAccess as necessary.
- enum AccessLattice {
- NoAccess = 0,
- RefAccess = 1,
- ModAccess = 2,
- ModRefAccess = RefAccess | ModAccess
- };
- unsigned Access : 2;
+ /// the memory, or whether it does both. The lattice goes from NoModRef to
+ /// either Ref or Mod, then to ModRef as necessary.
+ ModRefInfo Access : 2;
/// The kind of alias relationship between pointers of the set.
///
@@ -193,8 +188,8 @@ class AliasSet : public ilist_node<AliasSet> {
AliasSet &operator=(const AliasSet &) = delete;
/// Accessors...
- bool isRef() const { return Access & RefAccess; }
- bool isMod() const { return Access & ModAccess; }
+ bool isRef() const { return isRefSet(Access); }
+ bool isMod() const { return isModSet(Access); }
bool isMustAlias() const { return Alias == SetMustAlias; }
bool isMayAlias() const { return Alias == SetMayAlias; }
@@ -260,8 +255,8 @@ class AliasSet : public ilist_node<AliasSet> {
private:
// Can only be created by AliasSetTracker.
AliasSet()
- : PtrListEnd(&PtrList), RefCount(0), AliasAny(false), Access(NoAccess),
- Alias(SetMustAlias) {}
+ : PtrListEnd(&PtrList), RefCount(0), AliasAny(false),
+ Access(ModRefInfo::NoModRef), Alias(SetMustAlias) {}
PointerRec *getSomePointer() const {
return PtrList;
@@ -388,7 +383,7 @@ class AliasSetTracker {
return *Entry;
}
- AliasSet &addPointer(MemoryLocation Loc, AliasSet::AccessLattice E);
+ AliasSet &addPointer(MemoryLocation Loc, ModRefInfo E);
AliasSet *mergeAliasSetsForPointer(const Value *Ptr, LocationSize Size,
const AAMDNodes &AAInfo,
bool &MustAliasAll);
diff --git a/llvm/lib/Analysis/AliasSetTracker.cpp b/llvm/lib/Analysis/AliasSetTracker.cpp
index 1c9ebadf36493..93e222f3d1aaf 100644
--- a/llvm/lib/Analysis/AliasSetTracker.cpp
+++ b/llvm/lib/Analysis/AliasSetTracker.cpp
@@ -47,7 +47,7 @@ void AliasSet::mergeSetIn(AliasSet &AS, AliasSetTracker &AST,
bool WasMustAlias = (Alias == SetMustAlias);
// Update the alias and access types of this set...
- Access |= AS.Access;
+ Access = Access | AS.Access;
Alias |= AS.Alias;
if (Alias == SetMustAlias) {
@@ -173,13 +173,13 @@ void AliasSet::addUnknownInst(Instruction *I, BatchAAResults &AA) {
!(I->use_empty() && match(I, m_Intrinsic<Intrinsic::invariant_start>()));
if (!MayWriteMemory) {
Alias = SetMayAlias;
- Access |= RefAccess;
+ Access = Access | ModRefInfo::Ref;
return;
}
// FIXME: This should use mod/ref information to make this not suck so bad
Alias = SetMayAlias;
- Access = ModRefAccess;
+ Access = ModRefInfo::ModRef;
}
/// aliasesPointer - If the specified pointer "may" (or must) alias one of the
@@ -368,32 +368,32 @@ AliasSet &AliasSetTracker::getAliasSetFor(const MemoryLocation &MemLoc) {
void AliasSetTracker::add(Value *Ptr, LocationSize Size,
const AAMDNodes &AAInfo) {
- addPointer(MemoryLocation(Ptr, Size, AAInfo), AliasSet::NoAccess);
+ addPointer(MemoryLocation(Ptr, Size, AAInfo), ModRefInfo::NoModRef);
}
void AliasSetTracker::add(LoadInst *LI) {
if (isStrongerThanMonotonic(LI->getOrdering()))
return addUnknown(LI);
- addPointer(MemoryLocation::get(LI), AliasSet::RefAccess);
+ addPointer(MemoryLocation::get(LI), ModRefInfo::Ref);
}
void AliasSetTracker::add(StoreInst *SI) {
if (isStrongerThanMonotonic(SI->getOrdering()))
return addUnknown(SI);
- addPointer(MemoryLocation::get(SI), AliasSet::ModAccess);
+ addPointer(MemoryLocation::get(SI), ModRefInfo::Mod);
}
void AliasSetTracker::add(VAArgInst *VAAI) {
- addPointer(MemoryLocation::get(VAAI), AliasSet::ModRefAccess);
+ addPointer(MemoryLocation::get(VAAI), ModRefInfo::ModRef);
}
void AliasSetTracker::add(AnyMemSetInst *MSI) {
- addPointer(MemoryLocation::getForDest(MSI), AliasSet::ModAccess);
+ addPointer(MemoryLocation::getForDest(MSI), ModRefInfo::Mod);
}
void AliasSetTracker::add(AnyMemTransferInst *MTI) {
- addPointer(MemoryLocation::getForDest(MTI), AliasSet::ModAccess);
- addPointer(MemoryLocation::getForSource(MTI), AliasSet::RefAccess);
+ addPointer(MemoryLocation::getForDest(MTI), ModRefInfo::Mod);
+ addPointer(MemoryLocation::getForSource(MTI), ModRefInfo::Ref);
}
void AliasSetTracker::addUnknown(Instruction *Inst) {
@@ -441,17 +441,6 @@ void AliasSetTracker::add(Instruction *I) {
// Handle all calls with known mod/ref sets genericall
if (auto *Call = dyn_cast<CallBase>(I))
if (Call->onlyAccessesArgMemory()) {
- auto getAccessFromModRef = [](ModRefInfo MRI) {
- if (isRefSet(MRI) && isModSet(MRI))
- return AliasSet::ModRefAccess;
- else if (isModSet(MRI))
- return AliasSet::ModAccess;
- else if (isRefSet(MRI))
- return AliasSet::RefAccess;
- else
- return AliasSet::NoAccess;
- };
-
ModRefInfo CallMask = AA.getMemoryEffects(Call).getModRef();
// Some intrinsics are marked as modifying memory for control flow
@@ -472,7 +461,7 @@ void AliasSetTracker::add(Instruction *I) {
ModRefInfo ArgMask = AA.getArgModRefInfo(Call, ArgIdx);
ArgMask &= CallMask;
if (!isNoModRef(ArgMask))
- addPointer(ArgLoc, getAccessFromModRef(ArgMask));
+ addPointer(ArgLoc, ArgMask);
}
return;
}
@@ -504,7 +493,7 @@ void AliasSetTracker::add(const AliasSetTracker &AST) {
for (AliasSet::iterator ASI = AS.begin(), E = AS.end(); ASI != E; ++ASI)
addPointer(
MemoryLocation(ASI.getPointer(), ASI.getSize(), ASI.getAAInfo()),
- (AliasSet::AccessLattice)AS.Access);
+ AS.Access);
}
}
@@ -525,7 +514,7 @@ AliasSet &AliasSetTracker::mergeAllAliasSets() {
AliasSets.push_back(new AliasSet());
AliasAnyAS = &AliasSets.back();
AliasAnyAS->Alias = AliasSet::SetMayAlias;
- AliasAnyAS->Access = AliasSet::ModRefAccess;
+ AliasAnyAS->Access = ModRefInfo::ModRef;
AliasAnyAS->AliasAny = true;
for (auto *Cur : ASVector) {
@@ -546,9 +535,9 @@ AliasSet &AliasSetTracker::mergeAllAliasSets() {
}
AliasSet &AliasSetTracker::addPointer(MemoryLocation Loc,
- AliasSet::AccessLattice E) {
+ ModRefInfo MRI) {
AliasSet &AS = getAliasSetFor(Loc);
- AS.Access |= E;
+ AS.Access = AS.Access | MRI;
if (!AliasAnyAS && (TotalMayAliasSetSize > SaturationThreshold)) {
// The AST is now saturated. From here on, we conservatively consider all
@@ -567,10 +556,10 @@ void AliasSet::print(raw_ostream &OS) const {
OS << " AliasSet[" << (const void*)this << ", " << RefCount << "] ";
OS << (Alias == SetMustAlias ? "must" : "may") << " alias, ";
switch (Access) {
- case NoAccess: OS << "No access "; break;
- case RefAccess: OS << "Ref "; break;
- case ModAccess: OS << "Mod "; break;
- case ModRefAccess: OS << "Mod/Ref "; break;
+ case ModRefInfo::NoModRef: OS << "No access "; break;
+ case ModRefInfo::Ref: OS << "Ref "; break;
+ case ModRefInfo::Mod: OS << "Mod "; break;
+ case ModRefInfo::ModRef: OS << "Mod/Ref "; break;
default: llvm_unreachable("Bad value for Access!");
}
if (Forward)
More information about the llvm-commits
mailing list