Skip to content

Commit d020fa2

Browse files
davidtgoldblattDavid Goldblatt
authored andcommitted
[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
1 parent c75b331 commit d020fa2

File tree

8 files changed

+40
-42
lines changed

8 files changed

+40
-42
lines changed

llvm/lib/Analysis/BasicAliasAnalysis.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ ModRefInfo BasicAAResult::getModRefInfoMask(const MemoryLocation &Loc,
731731
// global to be marked constant in some modules and non-constant in
732732
// others. GV may even be a declaration, not a definition.
733733
if (!GV->isConstant())
734-
return AAResultBase::getModRefInfoMask(Loc, AAQI, IgnoreLocals);
734+
return ModRefInfo::ModRef;
735735
continue;
736736
}
737737

@@ -747,18 +747,18 @@ ModRefInfo BasicAAResult::getModRefInfoMask(const MemoryLocation &Loc,
747747
if (const PHINode *PN = dyn_cast<PHINode>(V)) {
748748
// Don't bother inspecting phi nodes with many operands.
749749
if (PN->getNumIncomingValues() > MaxLookup)
750-
return AAResultBase::getModRefInfoMask(Loc, AAQI, IgnoreLocals);
750+
return ModRefInfo::ModRef;
751751
append_range(Worklist, PN->incoming_values());
752752
continue;
753753
}
754754

755755
// Otherwise be conservative.
756-
return AAResultBase::getModRefInfoMask(Loc, AAQI, IgnoreLocals);
756+
return ModRefInfo::ModRef;
757757
} while (!Worklist.empty() && --MaxLookup);
758758

759759
// If we hit the maximum number of instructions to examine, be conservative.
760760
if (!Worklist.empty())
761-
return AAResultBase::getModRefInfoMask(Loc, AAQI, IgnoreLocals);
761+
return ModRefInfo::ModRef;
762762

763763
return Result;
764764
}
@@ -813,7 +813,7 @@ ModRefInfo BasicAAResult::getArgModRefInfo(const CallBase *Call,
813813
if (Call->paramHasAttr(ArgIdx, Attribute::ReadNone))
814814
return ModRefInfo::NoModRef;
815815

816-
return AAResultBase::getArgModRefInfo(Call, ArgIdx);
816+
return ModRefInfo::ModRef;
817817
}
818818

819819
#ifndef NDEBUG
@@ -972,8 +972,8 @@ ModRefInfo BasicAAResult::getModRefInfo(const CallBase *Call,
972972
if (isIntrinsicCall(Call, Intrinsic::invariant_start))
973973
return ModRefInfo::Ref;
974974

975-
// The AAResultBase base class has some smarts, lets use them.
976-
return AAResultBase::getModRefInfo(Call, Loc, AAQI);
975+
// Be conservative.
976+
return ModRefInfo::ModRef;
977977
}
978978

979979
ModRefInfo BasicAAResult::getModRefInfo(const CallBase *Call1,
@@ -1000,8 +1000,8 @@ ModRefInfo BasicAAResult::getModRefInfo(const CallBase *Call1,
10001000
? ModRefInfo::Mod
10011001
: ModRefInfo::NoModRef;
10021002

1003-
// The AAResultBase base class has some smarts, lets use them.
1004-
return AAResultBase::getModRefInfo(Call1, Call2, AAQI);
1003+
// Be conservative.
1004+
return ModRefInfo::ModRef;
10051005
}
10061006

10071007
/// Return true if we know V to the base address of the corresponding memory

llvm/lib/Analysis/GlobalsModRef.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ MemoryEffects GlobalsAAResult::getMemoryEffects(const Function *F) {
241241
if (FunctionInfo *FI = getFunctionInfo(F))
242242
return MemoryEffects(FI->getModRefInfo());
243243

244-
return AAResultBase::getMemoryEffects(F);
244+
return MemoryEffects::unknown();
245245
}
246246

247247
/// Returns the function info for the function, or null if we don't have
@@ -791,10 +791,7 @@ bool GlobalsAAResult::isNonEscapingGlobalNoAlias(const GlobalValue *GV,
791791

792792
// FIXME: It would be good to handle other obvious no-alias cases here, but
793793
// it isn't clear how to do so reasonably without building a small version
794-
// of BasicAA into this code. We could recurse into AAResultBase::alias
795-
// here but that seems likely to go poorly as we're inside the
796-
// implementation of such a query. Until then, just conservatively return
797-
// false.
794+
// of BasicAA into this code.
798795
return false;
799796
} while (!Inputs.empty());
800797

@@ -892,7 +889,7 @@ AliasResult GlobalsAAResult::alias(const MemoryLocation &LocA,
892889
if ((GV1 || GV2) && GV1 != GV2)
893890
return AliasResult::NoAlias;
894891

895-
return AAResultBase::alias(LocA, LocB, AAQI, nullptr);
892+
return AliasResult::MayAlias;
896893
}
897894

898895
ModRefInfo GlobalsAAResult::getModRefInfoForArgument(const CallBase *Call,

llvm/lib/Analysis/ObjCARCAliasAnalysis.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
/// TODO: Theoretically we could check for dependencies between objc_* calls
2121
/// and FMRB_OnlyAccessesArgumentPointees calls or other well-behaved calls.
2222
///
23+
/// TODO: The calls here to AAResultBase member functions are all effectively
24+
/// no-ops that just return a conservative result. The original intent was to
25+
/// chain to another analysis for a recursive query, but this was lost in a
26+
/// refactor. These should instead be rephrased in terms of queries to AAQI.AAR.
27+
///
2328
//===----------------------------------------------------------------------===//
2429

2530
#include "llvm/Analysis/ObjCARCAliasAnalysis.h"

llvm/lib/Analysis/ScalarEvolutionAliasAnalysis.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ AliasResult SCEVAAResult::alias(const MemoryLocation &LocA,
105105
AAQI, nullptr) == AliasResult::NoAlias)
106106
return AliasResult::NoAlias;
107107

108-
// Forward the query to the next analysis.
109-
return AAResultBase::alias(LocA, LocB, AAQI, nullptr);
108+
return AliasResult::MayAlias;
110109
}
111110

112111
/// Given an expression, try to find a base value.

llvm/lib/Analysis/ScopedNoAliasAA.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ AliasResult ScopedNoAliasAAResult::alias(const MemoryLocation &LocA,
5656
AAQueryInfo &AAQI,
5757
const Instruction *) {
5858
if (!EnableScopedNoAlias)
59-
return AAResultBase::alias(LocA, LocB, AAQI, nullptr);
59+
return AliasResult::MayAlias;
6060

6161
// Get the attached MDNodes.
6262
const MDNode *AScopes = LocA.AATags.Scope, *BScopes = LocB.AATags.Scope;
@@ -69,15 +69,14 @@ AliasResult ScopedNoAliasAAResult::alias(const MemoryLocation &LocA,
6969
if (!mayAliasInScopes(BScopes, ANoAlias))
7070
return AliasResult::NoAlias;
7171

72-
// If they may alias, chain to the next AliasAnalysis.
73-
return AAResultBase::alias(LocA, LocB, AAQI, nullptr);
72+
return AliasResult::MayAlias;
7473
}
7574

7675
ModRefInfo ScopedNoAliasAAResult::getModRefInfo(const CallBase *Call,
7776
const MemoryLocation &Loc,
7877
AAQueryInfo &AAQI) {
7978
if (!EnableScopedNoAlias)
80-
return AAResultBase::getModRefInfo(Call, Loc, AAQI);
79+
return ModRefInfo::ModRef;
8180

8281
if (!mayAliasInScopes(Loc.AATags.Scope,
8382
Call->getMetadata(LLVMContext::MD_noalias)))
@@ -87,14 +86,14 @@ ModRefInfo ScopedNoAliasAAResult::getModRefInfo(const CallBase *Call,
8786
Loc.AATags.NoAlias))
8887
return ModRefInfo::NoModRef;
8988

90-
return AAResultBase::getModRefInfo(Call, Loc, AAQI);
89+
return ModRefInfo::ModRef;
9190
}
9291

9392
ModRefInfo ScopedNoAliasAAResult::getModRefInfo(const CallBase *Call1,
9493
const CallBase *Call2,
9594
AAQueryInfo &AAQI) {
9695
if (!EnableScopedNoAlias)
97-
return AAResultBase::getModRefInfo(Call1, Call2, AAQI);
96+
return ModRefInfo::ModRef;
9897

9998
if (!mayAliasInScopes(Call1->getMetadata(LLVMContext::MD_alias_scope),
10099
Call2->getMetadata(LLVMContext::MD_noalias)))
@@ -104,7 +103,7 @@ ModRefInfo ScopedNoAliasAAResult::getModRefInfo(const CallBase *Call1,
104103
Call1->getMetadata(LLVMContext::MD_noalias)))
105104
return ModRefInfo::NoModRef;
106105

107-
return AAResultBase::getModRefInfo(Call1, Call2, AAQI);
106+
return ModRefInfo::ModRef;
108107
}
109108

110109
static void collectMDInDomain(const MDNode *List, const MDNode *Domain,

llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -375,11 +375,10 @@ AliasResult TypeBasedAAResult::alias(const MemoryLocation &LocA,
375375
const MemoryLocation &LocB,
376376
AAQueryInfo &AAQI, const Instruction *) {
377377
if (!EnableTBAA)
378-
return AAResultBase::alias(LocA, LocB, AAQI, nullptr);
378+
return AliasResult::MayAlias;
379379

380-
// If accesses may alias, chain to the next AliasAnalysis.
381380
if (Aliases(LocA.AATags.TBAA, LocB.AATags.TBAA))
382-
return AAResultBase::alias(LocA, LocB, AAQI, nullptr);
381+
return AliasResult::MayAlias;
383382

384383
// Otherwise return a definitive result.
385384
return AliasResult::NoAlias;
@@ -389,66 +388,66 @@ ModRefInfo TypeBasedAAResult::getModRefInfoMask(const MemoryLocation &Loc,
389388
AAQueryInfo &AAQI,
390389
bool IgnoreLocals) {
391390
if (!EnableTBAA)
392-
return AAResultBase::getModRefInfoMask(Loc, AAQI, IgnoreLocals);
391+
return ModRefInfo::ModRef;
393392

394393
const MDNode *M = Loc.AATags.TBAA;
395394
if (!M)
396-
return AAResultBase::getModRefInfoMask(Loc, AAQI, IgnoreLocals);
395+
return ModRefInfo::ModRef;
397396

398397
// If this is an "immutable" type, we can assume the pointer is pointing
399398
// to constant memory.
400399
if ((!isStructPathTBAA(M) && TBAANode(M).isTypeImmutable()) ||
401400
(isStructPathTBAA(M) && TBAAStructTagNode(M).isTypeImmutable()))
402401
return ModRefInfo::NoModRef;
403402

404-
return AAResultBase::getModRefInfoMask(Loc, AAQI, IgnoreLocals);
403+
return ModRefInfo::ModRef;
405404
}
406405

407406
MemoryEffects TypeBasedAAResult::getMemoryEffects(const CallBase *Call,
408407
AAQueryInfo &AAQI) {
409408
if (!EnableTBAA)
410-
return AAResultBase::getMemoryEffects(Call, AAQI);
409+
return MemoryEffects::unknown();
411410

412411
// If this is an "immutable" type, the access is not observable.
413412
if (const MDNode *M = Call->getMetadata(LLVMContext::MD_tbaa))
414413
if ((!isStructPathTBAA(M) && TBAANode(M).isTypeImmutable()) ||
415414
(isStructPathTBAA(M) && TBAAStructTagNode(M).isTypeImmutable()))
416415
return MemoryEffects::none();
417416

418-
return AAResultBase::getMemoryEffects(Call, AAQI);
417+
return MemoryEffects::unknown();
419418
}
420419

421420
MemoryEffects TypeBasedAAResult::getMemoryEffects(const Function *F) {
422-
// Functions don't have metadata. Just chain to the next implementation.
423-
return AAResultBase::getMemoryEffects(F);
421+
// Functions don't have metadata.
422+
return MemoryEffects::unknown();
424423
}
425424

426425
ModRefInfo TypeBasedAAResult::getModRefInfo(const CallBase *Call,
427426
const MemoryLocation &Loc,
428427
AAQueryInfo &AAQI) {
429428
if (!EnableTBAA)
430-
return AAResultBase::getModRefInfo(Call, Loc, AAQI);
429+
return ModRefInfo::ModRef;
431430

432431
if (const MDNode *L = Loc.AATags.TBAA)
433432
if (const MDNode *M = Call->getMetadata(LLVMContext::MD_tbaa))
434433
if (!Aliases(L, M))
435434
return ModRefInfo::NoModRef;
436435

437-
return AAResultBase::getModRefInfo(Call, Loc, AAQI);
436+
return ModRefInfo::ModRef;
438437
}
439438

440439
ModRefInfo TypeBasedAAResult::getModRefInfo(const CallBase *Call1,
441440
const CallBase *Call2,
442441
AAQueryInfo &AAQI) {
443442
if (!EnableTBAA)
444-
return AAResultBase::getModRefInfo(Call1, Call2, AAQI);
443+
return ModRefInfo::ModRef;
445444

446445
if (const MDNode *M1 = Call1->getMetadata(LLVMContext::MD_tbaa))
447446
if (const MDNode *M2 = Call2->getMetadata(LLVMContext::MD_tbaa))
448447
if (!Aliases(M1, M2))
449448
return ModRefInfo::NoModRef;
450449

451-
return AAResultBase::getModRefInfo(Call1, Call2, AAQI);
450+
return ModRefInfo::ModRef;
452451
}
453452

454453
bool MDNode::isTBAAVtableAccess() const {

llvm/lib/Target/AMDGPU/AMDGPUAliasAnalysis.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ AliasResult AMDGPUAAResult::alias(const MemoryLocation &LocA,
9393
}
9494
}
9595

96-
// Forward the query to the next alias analysis.
97-
return AAResultBase::alias(LocA, LocB, AAQI, nullptr);
96+
return AliasResult::MayAlias;
9897
}
9998

10099
ModRefInfo AMDGPUAAResult::getModRefInfoMask(const MemoryLocation &Loc,
@@ -111,5 +110,5 @@ ModRefInfo AMDGPUAAResult::getModRefInfoMask(const MemoryLocation &Loc,
111110
AS == AMDGPUAS::CONSTANT_ADDRESS_32BIT)
112111
return ModRefInfo::NoModRef;
113112

114-
return AAResultBase::getModRefInfoMask(Loc, AAQI, IgnoreLocals);
113+
return ModRefInfo::ModRef;
115114
}

llvm/lib/Target/NVPTX/NVPTXAliasAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,5 @@ ModRefInfo NVPTXAAResult::getModRefInfoMask(const MemoryLocation &Loc,
9494
if (isConstOrParam(Base->getType()->getPointerAddressSpace()))
9595
return ModRefInfo::NoModRef;
9696

97-
return AAResultBase::getModRefInfoMask(Loc, AAQI, IgnoreLocals);
97+
return ModRefInfo::ModRef;
9898
}

0 commit comments

Comments
 (0)