[LAA] Use LoopAccessInfoManager in legacy pass.

Simplify LoopAccessLegacyAnalysis by using LoopAccessInfoManager from
D134606. As a side-effect this also removes printing support from
LoopAccessLegacyAnalysis.

Depends on D134606.

Reviewed By: aeubanks

Differential Revision: https://reviews.llvm.org/D134608
This commit is contained in:
Florian Hahn 2022-10-04 08:37:11 +01:00
parent 1303abe658
commit db720dc17c
No known key found for this signature in database
GPG Key ID: EEF712BB5E80EBBA
2 changed files with 11 additions and 40 deletions

View File

@ -781,6 +781,8 @@ public:
: 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 @@ public:
/// 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<Loop *, std::unique_ptr<LoopAccessInfo>> LoopAccessInfoMap;
// The used analysis passes.
ScalarEvolution *SE = nullptr;
const TargetLibraryInfo *TLI = nullptr;
AAResults *AA = nullptr;
DominatorTree *DT = nullptr;
LoopInfo *LI = nullptr;
std::unique_ptr<LoopAccessInfoManager> LAIs;
};
/// This analysis provides dependence information for the memory

View File

@ -2683,34 +2683,14 @@ LoopAccessLegacyAnalysis::LoopAccessLegacyAnalysis() : FunctionPass(ID) {
initializeLoopAccessLegacyAnalysisPass(*PassRegistry::getPassRegistry());
}
const LoopAccessInfo &LoopAccessLegacyAnalysis::getInfo(Loop *L) {
auto &LAI = LoopAccessInfoMap[L];
if (!LAI)
LAI = std::make_unique<LoopAccessInfo>(L, SE, TLI, AA, DT, LI);
return *LAI;
}
void LoopAccessLegacyAnalysis::print(raw_ostream &OS, const Module *M) const {
LoopAccessLegacyAnalysis &LAA = *const_cast<LoopAccessLegacyAnalysis *>(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<ScalarEvolutionWrapperPass>().getSE();
auto &SE = getAnalysis<ScalarEvolutionWrapperPass>().getSE();
auto *TLIP = getAnalysisIfAvailable<TargetLibraryInfoWrapperPass>();
TLI = TLIP ? &TLIP->getTLI(F) : nullptr;
AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
auto *TLI = TLIP ? &TLIP->getTLI(F) : nullptr;
auto &AA = getAnalysis<AAResultsWrapperPass>().getAAResults();
auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
auto &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
LAIs = std::make_unique<LoopAccessInfoManager>(SE, AA, DT, LI, TLI);
return false;
}