[llvm] d020fa2 - [AA] Skip the layer of indirection in returning conservative results.
David Goldblatt via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 28 12:28:22 PDT 2023
Author: David Goldblatt
Date: 2023-07-28T12:13:35-07:00
New Revision: d020fa2b29d84b877d1e43dbfb3418275857bf87
URL: https://github.com/llvm/llvm-project/commit/d020fa2b29d84b877d1e43dbfb3418275857bf87
DIFF: https://github.com/llvm/llvm-project/commit/d020fa2b29d84b877d1e43dbfb3418275857bf87.diff
LOG: [AA] Skip the layer of indirection in returning conservative results.
Historically, AA implementations chained to a following implementation
to answer recursive queries. This is no longer the case, but the legacy
lives on in a confusing phrasing of the return-a-conservative-value
paths. Let's just return "don't know" directly, where appropriate; the
current two-step way is confusing.
Differential Revision: https://reviews.llvm.org/D149100
Added:
Modified:
llvm/lib/Analysis/BasicAliasAnalysis.cpp
llvm/lib/Analysis/GlobalsModRef.cpp
llvm/lib/Analysis/ObjCARCAliasAnalysis.cpp
llvm/lib/Analysis/ScalarEvolutionAliasAnalysis.cpp
llvm/lib/Analysis/ScopedNoAliasAA.cpp
llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp
llvm/lib/Target/AMDGPU/AMDGPUAliasAnalysis.cpp
llvm/lib/Target/NVPTX/NVPTXAliasAnalysis.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index 16e0e1f66524fa..c162b8f6edc190 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -731,7 +731,7 @@ ModRefInfo BasicAAResult::getModRefInfoMask(const MemoryLocation &Loc,
// global to be marked constant in some modules and non-constant in
// others. GV may even be a declaration, not a definition.
if (!GV->isConstant())
- return AAResultBase::getModRefInfoMask(Loc, AAQI, IgnoreLocals);
+ return ModRefInfo::ModRef;
continue;
}
@@ -747,18 +747,18 @@ ModRefInfo BasicAAResult::getModRefInfoMask(const MemoryLocation &Loc,
if (const PHINode *PN = dyn_cast<PHINode>(V)) {
// Don't bother inspecting phi nodes with many operands.
if (PN->getNumIncomingValues() > MaxLookup)
- return AAResultBase::getModRefInfoMask(Loc, AAQI, IgnoreLocals);
+ return ModRefInfo::ModRef;
append_range(Worklist, PN->incoming_values());
continue;
}
// Otherwise be conservative.
- return AAResultBase::getModRefInfoMask(Loc, AAQI, IgnoreLocals);
+ return ModRefInfo::ModRef;
} while (!Worklist.empty() && --MaxLookup);
// If we hit the maximum number of instructions to examine, be conservative.
if (!Worklist.empty())
- return AAResultBase::getModRefInfoMask(Loc, AAQI, IgnoreLocals);
+ return ModRefInfo::ModRef;
return Result;
}
@@ -813,7 +813,7 @@ ModRefInfo BasicAAResult::getArgModRefInfo(const CallBase *Call,
if (Call->paramHasAttr(ArgIdx, Attribute::ReadNone))
return ModRefInfo::NoModRef;
- return AAResultBase::getArgModRefInfo(Call, ArgIdx);
+ return ModRefInfo::ModRef;
}
#ifndef NDEBUG
@@ -972,8 +972,8 @@ ModRefInfo BasicAAResult::getModRefInfo(const CallBase *Call,
if (isIntrinsicCall(Call, Intrinsic::invariant_start))
return ModRefInfo::Ref;
- // The AAResultBase base class has some smarts, lets use them.
- return AAResultBase::getModRefInfo(Call, Loc, AAQI);
+ // Be conservative.
+ return ModRefInfo::ModRef;
}
ModRefInfo BasicAAResult::getModRefInfo(const CallBase *Call1,
@@ -1000,8 +1000,8 @@ ModRefInfo BasicAAResult::getModRefInfo(const CallBase *Call1,
? ModRefInfo::Mod
: ModRefInfo::NoModRef;
- // The AAResultBase base class has some smarts, lets use them.
- return AAResultBase::getModRefInfo(Call1, Call2, AAQI);
+ // Be conservative.
+ return ModRefInfo::ModRef;
}
/// Return true if we know V to the base address of the corresponding memory
diff --git a/llvm/lib/Analysis/GlobalsModRef.cpp b/llvm/lib/Analysis/GlobalsModRef.cpp
index c218b3d511e202..527f19b194eeb9 100644
--- a/llvm/lib/Analysis/GlobalsModRef.cpp
+++ b/llvm/lib/Analysis/GlobalsModRef.cpp
@@ -241,7 +241,7 @@ MemoryEffects GlobalsAAResult::getMemoryEffects(const Function *F) {
if (FunctionInfo *FI = getFunctionInfo(F))
return MemoryEffects(FI->getModRefInfo());
- return AAResultBase::getMemoryEffects(F);
+ return MemoryEffects::unknown();
}
/// Returns the function info for the function, or null if we don't have
@@ -791,10 +791,7 @@ bool GlobalsAAResult::isNonEscapingGlobalNoAlias(const GlobalValue *GV,
// FIXME: It would be good to handle other obvious no-alias cases here, but
// it isn't clear how to do so reasonably without building a small version
- // of BasicAA into this code. We could recurse into AAResultBase::alias
- // here but that seems likely to go poorly as we're inside the
- // implementation of such a query. Until then, just conservatively return
- // false.
+ // of BasicAA into this code.
return false;
} while (!Inputs.empty());
@@ -892,7 +889,7 @@ AliasResult GlobalsAAResult::alias(const MemoryLocation &LocA,
if ((GV1 || GV2) && GV1 != GV2)
return AliasResult::NoAlias;
- return AAResultBase::alias(LocA, LocB, AAQI, nullptr);
+ return AliasResult::MayAlias;
}
ModRefInfo GlobalsAAResult::getModRefInfoForArgument(const CallBase *Call,
diff --git a/llvm/lib/Analysis/ObjCARCAliasAnalysis.cpp b/llvm/lib/Analysis/ObjCARCAliasAnalysis.cpp
index 1ccf792d2f8c62..ca87bc3c78bed0 100644
--- a/llvm/lib/Analysis/ObjCARCAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/ObjCARCAliasAnalysis.cpp
@@ -20,6 +20,11 @@
/// TODO: Theoretically we could check for dependencies between objc_* calls
/// and FMRB_OnlyAccessesArgumentPointees calls or other well-behaved calls.
///
+/// TODO: The calls here to AAResultBase member functions are all effectively
+/// no-ops that just return a conservative result. The original intent was to
+/// chain to another analysis for a recursive query, but this was lost in a
+/// refactor. These should instead be rephrased in terms of queries to AAQI.AAR.
+///
//===----------------------------------------------------------------------===//
#include "llvm/Analysis/ObjCARCAliasAnalysis.h"
diff --git a/llvm/lib/Analysis/ScalarEvolutionAliasAnalysis.cpp b/llvm/lib/Analysis/ScalarEvolutionAliasAnalysis.cpp
index 08f7a91ff9b283..b8f1f39da03e93 100644
--- a/llvm/lib/Analysis/ScalarEvolutionAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/ScalarEvolutionAliasAnalysis.cpp
@@ -105,8 +105,7 @@ AliasResult SCEVAAResult::alias(const MemoryLocation &LocA,
AAQI, nullptr) == AliasResult::NoAlias)
return AliasResult::NoAlias;
- // Forward the query to the next analysis.
- return AAResultBase::alias(LocA, LocB, AAQI, nullptr);
+ return AliasResult::MayAlias;
}
/// Given an expression, try to find a base value.
diff --git a/llvm/lib/Analysis/ScopedNoAliasAA.cpp b/llvm/lib/Analysis/ScopedNoAliasAA.cpp
index f16ac0ab04166f..3815bdf49d59ce 100644
--- a/llvm/lib/Analysis/ScopedNoAliasAA.cpp
+++ b/llvm/lib/Analysis/ScopedNoAliasAA.cpp
@@ -56,7 +56,7 @@ AliasResult ScopedNoAliasAAResult::alias(const MemoryLocation &LocA,
AAQueryInfo &AAQI,
const Instruction *) {
if (!EnableScopedNoAlias)
- return AAResultBase::alias(LocA, LocB, AAQI, nullptr);
+ return AliasResult::MayAlias;
// Get the attached MDNodes.
const MDNode *AScopes = LocA.AATags.Scope, *BScopes = LocB.AATags.Scope;
@@ -69,15 +69,14 @@ AliasResult ScopedNoAliasAAResult::alias(const MemoryLocation &LocA,
if (!mayAliasInScopes(BScopes, ANoAlias))
return AliasResult::NoAlias;
- // If they may alias, chain to the next AliasAnalysis.
- return AAResultBase::alias(LocA, LocB, AAQI, nullptr);
+ return AliasResult::MayAlias;
}
ModRefInfo ScopedNoAliasAAResult::getModRefInfo(const CallBase *Call,
const MemoryLocation &Loc,
AAQueryInfo &AAQI) {
if (!EnableScopedNoAlias)
- return AAResultBase::getModRefInfo(Call, Loc, AAQI);
+ return ModRefInfo::ModRef;
if (!mayAliasInScopes(Loc.AATags.Scope,
Call->getMetadata(LLVMContext::MD_noalias)))
@@ -87,14 +86,14 @@ ModRefInfo ScopedNoAliasAAResult::getModRefInfo(const CallBase *Call,
Loc.AATags.NoAlias))
return ModRefInfo::NoModRef;
- return AAResultBase::getModRefInfo(Call, Loc, AAQI);
+ return ModRefInfo::ModRef;
}
ModRefInfo ScopedNoAliasAAResult::getModRefInfo(const CallBase *Call1,
const CallBase *Call2,
AAQueryInfo &AAQI) {
if (!EnableScopedNoAlias)
- return AAResultBase::getModRefInfo(Call1, Call2, AAQI);
+ return ModRefInfo::ModRef;
if (!mayAliasInScopes(Call1->getMetadata(LLVMContext::MD_alias_scope),
Call2->getMetadata(LLVMContext::MD_noalias)))
@@ -104,7 +103,7 @@ ModRefInfo ScopedNoAliasAAResult::getModRefInfo(const CallBase *Call1,
Call1->getMetadata(LLVMContext::MD_noalias)))
return ModRefInfo::NoModRef;
- return AAResultBase::getModRefInfo(Call1, Call2, AAQI);
+ return ModRefInfo::ModRef;
}
static void collectMDInDomain(const MDNode *List, const MDNode *Domain,
diff --git a/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp b/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp
index 529f3a76d23e51..e4dc1a867f6f0c 100644
--- a/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp
@@ -375,11 +375,10 @@ AliasResult TypeBasedAAResult::alias(const MemoryLocation &LocA,
const MemoryLocation &LocB,
AAQueryInfo &AAQI, const Instruction *) {
if (!EnableTBAA)
- return AAResultBase::alias(LocA, LocB, AAQI, nullptr);
+ return AliasResult::MayAlias;
- // If accesses may alias, chain to the next AliasAnalysis.
if (Aliases(LocA.AATags.TBAA, LocB.AATags.TBAA))
- return AAResultBase::alias(LocA, LocB, AAQI, nullptr);
+ return AliasResult::MayAlias;
// Otherwise return a definitive result.
return AliasResult::NoAlias;
@@ -389,11 +388,11 @@ ModRefInfo TypeBasedAAResult::getModRefInfoMask(const MemoryLocation &Loc,
AAQueryInfo &AAQI,
bool IgnoreLocals) {
if (!EnableTBAA)
- return AAResultBase::getModRefInfoMask(Loc, AAQI, IgnoreLocals);
+ return ModRefInfo::ModRef;
const MDNode *M = Loc.AATags.TBAA;
if (!M)
- return AAResultBase::getModRefInfoMask(Loc, AAQI, IgnoreLocals);
+ return ModRefInfo::ModRef;
// If this is an "immutable" type, we can assume the pointer is pointing
// to constant memory.
@@ -401,13 +400,13 @@ ModRefInfo TypeBasedAAResult::getModRefInfoMask(const MemoryLocation &Loc,
(isStructPathTBAA(M) && TBAAStructTagNode(M).isTypeImmutable()))
return ModRefInfo::NoModRef;
- return AAResultBase::getModRefInfoMask(Loc, AAQI, IgnoreLocals);
+ return ModRefInfo::ModRef;
}
MemoryEffects TypeBasedAAResult::getMemoryEffects(const CallBase *Call,
AAQueryInfo &AAQI) {
if (!EnableTBAA)
- return AAResultBase::getMemoryEffects(Call, AAQI);
+ return MemoryEffects::unknown();
// If this is an "immutable" type, the access is not observable.
if (const MDNode *M = Call->getMetadata(LLVMContext::MD_tbaa))
@@ -415,40 +414,40 @@ MemoryEffects TypeBasedAAResult::getMemoryEffects(const CallBase *Call,
(isStructPathTBAA(M) && TBAAStructTagNode(M).isTypeImmutable()))
return MemoryEffects::none();
- return AAResultBase::getMemoryEffects(Call, AAQI);
+ return MemoryEffects::unknown();
}
MemoryEffects TypeBasedAAResult::getMemoryEffects(const Function *F) {
- // Functions don't have metadata. Just chain to the next implementation.
- return AAResultBase::getMemoryEffects(F);
+ // Functions don't have metadata.
+ return MemoryEffects::unknown();
}
ModRefInfo TypeBasedAAResult::getModRefInfo(const CallBase *Call,
const MemoryLocation &Loc,
AAQueryInfo &AAQI) {
if (!EnableTBAA)
- return AAResultBase::getModRefInfo(Call, Loc, AAQI);
+ return ModRefInfo::ModRef;
if (const MDNode *L = Loc.AATags.TBAA)
if (const MDNode *M = Call->getMetadata(LLVMContext::MD_tbaa))
if (!Aliases(L, M))
return ModRefInfo::NoModRef;
- return AAResultBase::getModRefInfo(Call, Loc, AAQI);
+ return ModRefInfo::ModRef;
}
ModRefInfo TypeBasedAAResult::getModRefInfo(const CallBase *Call1,
const CallBase *Call2,
AAQueryInfo &AAQI) {
if (!EnableTBAA)
- return AAResultBase::getModRefInfo(Call1, Call2, AAQI);
+ return ModRefInfo::ModRef;
if (const MDNode *M1 = Call1->getMetadata(LLVMContext::MD_tbaa))
if (const MDNode *M2 = Call2->getMetadata(LLVMContext::MD_tbaa))
if (!Aliases(M1, M2))
return ModRefInfo::NoModRef;
- return AAResultBase::getModRefInfo(Call1, Call2, AAQI);
+ return ModRefInfo::ModRef;
}
bool MDNode::isTBAAVtableAccess() const {
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAliasAnalysis.cpp b/llvm/lib/Target/AMDGPU/AMDGPUAliasAnalysis.cpp
index 63942414bf3c52..8d3eac6868318e 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAliasAnalysis.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAliasAnalysis.cpp
@@ -93,8 +93,7 @@ AliasResult AMDGPUAAResult::alias(const MemoryLocation &LocA,
}
}
- // Forward the query to the next alias analysis.
- return AAResultBase::alias(LocA, LocB, AAQI, nullptr);
+ return AliasResult::MayAlias;
}
ModRefInfo AMDGPUAAResult::getModRefInfoMask(const MemoryLocation &Loc,
@@ -111,5 +110,5 @@ ModRefInfo AMDGPUAAResult::getModRefInfoMask(const MemoryLocation &Loc,
AS == AMDGPUAS::CONSTANT_ADDRESS_32BIT)
return ModRefInfo::NoModRef;
- return AAResultBase::getModRefInfoMask(Loc, AAQI, IgnoreLocals);
+ return ModRefInfo::ModRef;
}
diff --git a/llvm/lib/Target/NVPTX/NVPTXAliasAnalysis.cpp b/llvm/lib/Target/NVPTX/NVPTXAliasAnalysis.cpp
index b4f7e78cb1078a..4f106584eb0a94 100644
--- a/llvm/lib/Target/NVPTX/NVPTXAliasAnalysis.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXAliasAnalysis.cpp
@@ -94,5 +94,5 @@ ModRefInfo NVPTXAAResult::getModRefInfoMask(const MemoryLocation &Loc,
if (isConstOrParam(Base->getType()->getPointerAddressSpace()))
return ModRefInfo::NoModRef;
- return AAResultBase::getModRefInfoMask(Loc, AAQI, IgnoreLocals);
+ return ModRefInfo::ModRef;
}
More information about the llvm-commits
mailing list