diff --git a/llvm/include/llvm/Analysis/LoopAccessAnalysis.h b/llvm/include/llvm/Analysis/LoopAccessAnalysis.h --- a/llvm/include/llvm/Analysis/LoopAccessAnalysis.h +++ b/llvm/include/llvm/Analysis/LoopAccessAnalysis.h @@ -781,6 +781,8 @@ : SE(SE), AA(AA), DT(DT), LI(LI), TLI(TLI) {} const LoopAccessInfo &getInfo(Loop &L); + + void clear() { LoopAccessInfoMap.clear(); } }; /// This analysis provides dependence information for the memory accesses @@ -803,26 +805,15 @@ /// Query the result of the loop access information for the loop \p L. /// /// If there is no cached result available run the analysis. - const LoopAccessInfo &getInfo(Loop *L); + const LoopAccessInfo &getInfo(Loop *L) { return LAIs->getInfo(*L); } void releaseMemory() override { // Invalidate the cache when the pass is freed. - LoopAccessInfoMap.clear(); + LAIs->clear(); } - /// Print the result of the analysis when invoked with -analyze. - void print(raw_ostream &OS, const Module *M = nullptr) const override; - private: - /// The cache. - DenseMap> LoopAccessInfoMap; - - // The used analysis passes. - ScalarEvolution *SE = nullptr; - const TargetLibraryInfo *TLI = nullptr; - AAResults *AA = nullptr; - DominatorTree *DT = nullptr; - LoopInfo *LI = nullptr; + std::unique_ptr LAIs; }; /// This analysis provides dependence information for the memory 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 @@ -2683,34 +2683,14 @@ initializeLoopAccessLegacyAnalysisPass(*PassRegistry::getPassRegistry()); } -const LoopAccessInfo &LoopAccessLegacyAnalysis::getInfo(Loop *L) { - auto &LAI = LoopAccessInfoMap[L]; - - if (!LAI) - LAI = std::make_unique(L, SE, TLI, AA, DT, LI); - - return *LAI; -} - -void LoopAccessLegacyAnalysis::print(raw_ostream &OS, const Module *M) const { - LoopAccessLegacyAnalysis &LAA = *const_cast(this); - - for (Loop *TopLevelLoop : *LI) - for (Loop *L : depth_first(TopLevelLoop)) { - OS.indent(2) << L->getHeader()->getName() << ":\n"; - auto &LAI = LAA.getInfo(L); - LAI.print(OS, 4); - } -} - bool LoopAccessLegacyAnalysis::runOnFunction(Function &F) { - SE = &getAnalysis().getSE(); + auto &SE = getAnalysis().getSE(); auto *TLIP = getAnalysisIfAvailable(); - TLI = TLIP ? &TLIP->getTLI(F) : nullptr; - AA = &getAnalysis().getAAResults(); - DT = &getAnalysis().getDomTree(); - LI = &getAnalysis().getLoopInfo(); - + auto *TLI = TLIP ? &TLIP->getTLI(F) : nullptr; + auto &AA = getAnalysis().getAAResults(); + auto &DT = getAnalysis().getDomTree(); + auto &LI = getAnalysis().getLoopInfo(); + LAIs = std::make_unique(SE, AA, DT, LI, TLI); return false; }