diff --git a/llvm/include/llvm/Analysis/AliasSetTracker.h b/llvm/include/llvm/Analysis/AliasSetTracker.h --- a/llvm/include/llvm/Analysis/AliasSetTracker.h +++ b/llvm/include/llvm/Analysis/AliasSetTracker.h @@ -33,7 +33,6 @@ namespace llvm { -class AAResults; class AliasResult; class AliasSetTracker; class AnyMemSetInst; @@ -287,7 +286,7 @@ void addPointer(AliasSetTracker &AST, PointerRec &Entry, LocationSize Size, const AAMDNodes &AAInfo, bool KnownMustAlias = false, bool SkipSizeUpdate = false); - void addUnknownInst(Instruction *I, AAResults &AA); + void addUnknownInst(Instruction *I, BatchAAResults &AA); public: /// If the specified pointer "may" (or must) alias one of the members in the @@ -303,7 +302,7 @@ } class AliasSetTracker { - AAResults &AA; + BatchAAResults &AA; ilist AliasSets; using PointerMapType = DenseMap, AliasSet::PointerRec *>; @@ -314,7 +313,7 @@ public: /// Create an empty collection of AliasSets, and use the specified alias /// analysis object to disambiguate load and store addresses. - explicit AliasSetTracker(AAResults &AA) : AA(AA) {} + explicit AliasSetTracker(BatchAAResults &AA) : AA(AA) {} ~AliasSetTracker() { clear(); } /// These methods are used to add different types of instructions to the alias @@ -352,7 +351,7 @@ AliasSet &getAliasSetFor(const MemoryLocation &MemLoc); /// Return the underlying alias analysis object used by this tracker. - AAResults &getAliasAnalysis() const { return AA; } + BatchAAResults &getAliasAnalysis() const { return AA; } using iterator = ilist::iterator; using const_iterator = ilist::const_iterator; diff --git a/llvm/include/llvm/LinkAllPasses.h b/llvm/include/llvm/LinkAllPasses.h --- a/llvm/include/llvm/LinkAllPasses.h +++ b/llvm/include/llvm/LinkAllPasses.h @@ -227,7 +227,8 @@ llvm::TargetLibraryInfoImpl TLII; llvm::TargetLibraryInfo TLI(TLII); llvm::AliasAnalysis AA(TLI); - llvm::AliasSetTracker X(AA); + llvm::BatchAAResults BAA(AA); + llvm::AliasSetTracker X(BAA); X.add(nullptr, llvm::LocationSize::beforeOrAfterPointer(), llvm::AAMDNodes()); // for -print-alias-sets (void) llvm::AreStatisticsEnabled(); diff --git a/llvm/lib/Analysis/AliasSetTracker.cpp b/llvm/lib/Analysis/AliasSetTracker.cpp --- a/llvm/lib/Analysis/AliasSetTracker.cpp +++ b/llvm/lib/Analysis/AliasSetTracker.cpp @@ -132,7 +132,7 @@ if (isMustAlias()) if (PointerRec *P = getSomePointer()) { if (!KnownMustAlias) { - AliasAnalysis &AA = AST.getAliasAnalysis(); + BatchAAResults &AA = AST.getAliasAnalysis(); AliasResult Result = AA.alias( MemoryLocation(P->getValue(), P->getSize(), P->getAAInfo()), MemoryLocation(Entry.getValue(), Size, AAInfo)); @@ -161,7 +161,7 @@ AST.TotalMayAliasSetSize++; } -void AliasSet::addUnknownInst(Instruction *I, AliasAnalysis &AA) { +void AliasSet::addUnknownInst(Instruction *I, BatchAAResults &AA) { if (UnknownInsts.empty()) addRef(); UnknownInsts.emplace_back(I); @@ -271,12 +271,11 @@ bool &MustAliasAll) { AliasSet *FoundSet = nullptr; MustAliasAll = true; - BatchAAResults BatchAA(AA); for (AliasSet &AS : llvm::make_early_inc_range(*this)) { if (AS.Forward) continue; - AliasResult AR = AS.aliasesPointer(Ptr, Size, AAInfo, BatchAA); + AliasResult AR = AS.aliasesPointer(Ptr, Size, AAInfo, AA); if (AR == AliasResult::NoAlias) continue; @@ -288,7 +287,7 @@ FoundSet = &AS; } else { // Otherwise, we must merge the sets. - FoundSet->mergeSetIn(AS, *this, BatchAA); + FoundSet->mergeSetIn(AS, *this, AA); } } @@ -296,17 +295,16 @@ } AliasSet *AliasSetTracker::findAliasSetForUnknownInst(Instruction *Inst) { - BatchAAResults BatchAA(AA); AliasSet *FoundSet = nullptr; for (AliasSet &AS : llvm::make_early_inc_range(*this)) { - if (AS.Forward || !AS.aliasesUnknownInst(Inst, BatchAA)) + if (AS.Forward || !AS.aliasesUnknownInst(Inst, AA)) continue; if (!FoundSet) { // If this is the first alias set ptr can go into, remember it. FoundSet = &AS; } else { // Otherwise, we must merge the sets. - FoundSet->mergeSetIn(AS, *this, BatchAA); + FoundSet->mergeSetIn(AS, *this, AA); } } return FoundSet; @@ -525,7 +523,6 @@ AliasAnyAS->Access = AliasSet::ModRefAccess; AliasAnyAS->AliasAny = true; - BatchAAResults BatchAA(AA); for (auto *Cur : ASVector) { // If Cur was already forwarding, just forward to the new AS instead. AliasSet *FwdTo = Cur->Forward; @@ -537,7 +534,7 @@ } // Otherwise, perform the actual merge. - AliasAnyAS->mergeSetIn(*Cur, *this, BatchAA); + AliasAnyAS->mergeSetIn(*Cur, *this, AA); } return *AliasAnyAS; @@ -625,7 +622,8 @@ PreservedAnalyses AliasSetsPrinterPass::run(Function &F, FunctionAnalysisManager &AM) { auto &AA = AM.getResult(F); - AliasSetTracker Tracker(AA); + BatchAAResults BatchAA(AA); + AliasSetTracker Tracker(BatchAA); OS << "Alias sets for function '" << F.getName() << "':\n"; for (Instruction &I : instructions(F)) Tracker.add(&I); diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp --- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp +++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp @@ -622,7 +622,7 @@ AccessAnalysis(Loop *TheLoop, AAResults *AA, LoopInfo *LI, MemoryDepChecker::DepCandidates &DA, PredicatedScalarEvolution &PSE) - : TheLoop(TheLoop), AST(*AA), LI(LI), DepCands(DA), PSE(PSE) {} + : TheLoop(TheLoop), BAA(*AA), AST(BAA), LI(LI), DepCands(DA), PSE(PSE) {} /// Register a load and whether it is only read from. void addLoad(MemoryLocation &Loc, Type *AccessTy, bool IsReadOnly) { @@ -704,6 +704,9 @@ /// Set of pointers that are read only. SmallPtrSet ReadOnlyPtr; + /// Batched alias analysis results. + BatchAAResults BAA; + /// An alias set tracker to partition the access set by underlying object and //intrinsic property (such as TBAA metadata). AliasSetTracker AST; diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp --- a/llvm/lib/Transforms/Scalar/LICM.cpp +++ b/llvm/lib/Transforms/Scalar/LICM.cpp @@ -2267,7 +2267,8 @@ static SmallVector, 0> collectPromotionCandidates(MemorySSA *MSSA, AliasAnalysis *AA, Loop *L) { - AliasSetTracker AST(*AA); + BatchAAResults BatchAA(*AA); + AliasSetTracker AST(BatchAA); auto IsPotentiallyPromotable = [L](const Instruction *I) { if (const auto *SI = dyn_cast(I)) @@ -2296,7 +2297,6 @@ return {}; // Nothing to promote... // Discard any sets for which there is an aliasing non-promotable access. - BatchAAResults BatchAA(*AA); foreachMemoryAccess(MSSA, L, [&](Instruction *I) { if (AttemptingPromotion.contains(I)) return; diff --git a/llvm/lib/Transforms/Scalar/LoopRerollPass.cpp b/llvm/lib/Transforms/Scalar/LoopRerollPass.cpp --- a/llvm/lib/Transforms/Scalar/LoopRerollPass.cpp +++ b/llvm/lib/Transforms/Scalar/LoopRerollPass.cpp @@ -1224,13 +1224,14 @@ dbgs() << "LRR: " << KV.second.find_first() << "\t" << *KV.first << "\n"; }); + BatchAAResults BatchAA(*AA); for (unsigned Iter = 1; Iter < Scale; ++Iter) { // In addition to regular aliasing information, we need to look for // instructions from later (future) iterations that have side effects // preventing us from reordering them past other instructions with side // effects. bool FutureSideEffects = false; - AliasSetTracker AST(*AA); + AliasSetTracker AST(BatchAA); // The map between instructions in f(%iv.(i+1)) and f(%iv). DenseMap BaseMap; @@ -1327,7 +1328,6 @@ // tracker. If we do, then we depend on a future iteration, and we // can't reroll. if (RootInst->mayReadFromMemory()) { - BatchAAResults BatchAA(*AA); for (auto &K : AST) { if (K.aliasesUnknownInst(RootInst, BatchAA)) { LLVM_DEBUG(dbgs() << "LRR: iteration root match failed at " diff --git a/llvm/lib/Transforms/Scalar/LoopVersioningLICM.cpp b/llvm/lib/Transforms/Scalar/LoopVersioningLICM.cpp --- a/llvm/lib/Transforms/Scalar/LoopVersioningLICM.cpp +++ b/llvm/lib/Transforms/Scalar/LoopVersioningLICM.cpp @@ -256,7 +256,8 @@ /// LoopVersioningLICM. bool LoopVersioningLICM::legalLoopMemoryAccesses() { // Loop over the body of this loop, construct AST. - AliasSetTracker AST(*AA); + BatchAAResults BAA(*AA); + AliasSetTracker AST(BAA); for (auto *Block : CurLoop->getBlocks()) { // Ignore blocks in subloops. if (LI.getLoopFor(Block) == CurLoop) diff --git a/llvm/unittests/Analysis/AliasSetTrackerTest.cpp b/llvm/unittests/Analysis/AliasSetTrackerTest.cpp --- a/llvm/unittests/Analysis/AliasSetTrackerTest.cpp +++ b/llvm/unittests/Analysis/AliasSetTrackerTest.cpp @@ -68,7 +68,8 @@ // Initialize the alias set tracker for the @test function. Function *Test = M->getFunction("test"); ASSERT_NE(Test, nullptr); - AliasSetTracker AST(AA); + BatchAAResults BAA(AA); + AliasSetTracker AST(BAA); for (auto &BB : *Test) AST.add(BB); // There should be 2 disjoint alias sets. 1 from each call. diff --git a/polly/include/polly/ScopDetection.h b/polly/include/polly/ScopDetection.h --- a/polly/include/polly/ScopDetection.h +++ b/polly/include/polly/ScopDetection.h @@ -48,22 +48,20 @@ #include "polly/ScopDetectionDiagnostic.h" #include "polly/Support/ScopHelper.h" +#include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/AliasSetTracker.h" #include "llvm/Analysis/RegionInfo.h" #include "llvm/Analysis/ScalarEvolutionExpressions.h" #include "llvm/Pass.h" #include -namespace llvm { -class AAResults; -} // namespace llvm - namespace polly { using llvm::AAResults; using llvm::AliasSetTracker; using llvm::AnalysisInfoMixin; using llvm::AnalysisKey; using llvm::AnalysisUsage; +using llvm::BatchAAResults; using llvm::BranchInst; using llvm::CallInst; using llvm::DenseMap; @@ -142,6 +140,7 @@ /// Context variables for SCoP detection. struct DetectionContext { Region &CurRegion; // The region to check. + BatchAAResults BAA; // The batched alias analysis results. AliasSetTracker AST; // The AliasSetTracker to hold the alias information. bool Verifying; // If we are in the verification phase? @@ -189,7 +188,7 @@ /// Initialize a DetectionContext from scratch. DetectionContext(Region &R, AAResults &AA, bool Verify) - : CurRegion(R), AST(AA), Verifying(Verify), Log(&R) {} + : CurRegion(R), BAA(AA), AST(BAA), Verifying(Verify), Log(&R) {} }; /// Helper data structure to collect statistics about loop counts. diff --git a/polly/lib/Analysis/ScopBuilder.cpp b/polly/lib/Analysis/ScopBuilder.cpp --- a/polly/lib/Analysis/ScopBuilder.cpp +++ b/polly/lib/Analysis/ScopBuilder.cpp @@ -3205,7 +3205,8 @@ std::tuple> ScopBuilder::buildAliasGroupsForAccesses() { - AliasSetTracker AST(AA); + BatchAAResults BAA(AA); + AliasSetTracker AST(BAA); DenseMap PtrToAcc; DenseSet HasWriteAccess;