From cc58e8918b70d5698ec06c0b6e4c6e4c27971870 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sat, 1 May 2021 17:40:26 +0200 Subject: [PATCH] [SCEV] Simplify backedge count clearing (NFC) This seems to be a leftover from when the BackedgeTakenInfo stored multiple exit counts with manual memory management. At some point this was switchted to a simple vector, and there should be no need to micro-manage the clearing anymore. We can simply drop the loop from the map and the the destructor do its job. --- llvm/include/llvm/Analysis/ScalarEvolution.h | 3 --- llvm/lib/Analysis/ScalarEvolution.cpp | 34 ++++++---------------------- 2 files changed, 7 insertions(+), 30 deletions(-) diff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h index 414baac..e84b710 100644 --- a/llvm/include/llvm/Analysis/ScalarEvolution.h +++ b/llvm/include/llvm/Analysis/ScalarEvolution.h @@ -1461,9 +1461,6 @@ private: /// Return true if any backedge taken count expressions refer to the given /// subexpression. bool hasOperand(const SCEV *S, ScalarEvolution *SE) const; - - /// Invalidate this result and free associated memory. - void clear(); }; /// Cache the backedge-taken count of the loops for this function as they diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index f224ab2..4005597 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -7207,16 +7207,6 @@ void ScalarEvolution::forgetAllLoops() { } void ScalarEvolution::forgetLoop(const Loop *L) { - // Drop any stored trip count value. - auto RemoveLoopFromBackedgeMap = - [](DenseMap &Map, const Loop *L) { - auto BTCPos = Map.find(L); - if (BTCPos != Map.end()) { - BTCPos->second.clear(); - Map.erase(BTCPos); - } - }; - SmallVector LoopWorklist(1, L); SmallVector Worklist; SmallPtrSet Visited; @@ -7225,8 +7215,9 @@ void ScalarEvolution::forgetLoop(const Loop *L) { while (!LoopWorklist.empty()) { auto *CurrL = LoopWorklist.pop_back_val(); - RemoveLoopFromBackedgeMap(BackedgeTakenCounts, CurrL); - RemoveLoopFromBackedgeMap(PredicatedBackedgeTakenCounts, CurrL); + // Drop any stored trip count value. + BackedgeTakenCounts.erase(CurrL); + PredicatedBackedgeTakenCounts.erase(CurrL); // Drop information about predicated SCEV rewrites for this loop. for (auto I = PredicatedSCEVRewrites.begin(); @@ -7484,11 +7475,6 @@ ScalarEvolution::BackedgeTakenInfo::BackedgeTakenInfo( "No point in having a non-constant max backedge taken count!"); } -/// Invalidate this result and free the ExitNotTakenInfo array. -void ScalarEvolution::BackedgeTakenInfo::clear() { - ExitNotTaken.clear(); -} - /// Compute the number of times the backedge of the specified loop will execute. ScalarEvolution::BackedgeTakenInfo ScalarEvolution::computeBackedgeTakenCount(const Loop *L, @@ -12227,13 +12213,8 @@ ScalarEvolution::~ScalarEvolution() { ExprValueMap.clear(); ValueExprMap.clear(); HasRecMap.clear(); - - // Free any extra memory created for ExitNotTakenInfo in the unlikely event - // that a loop had multiple computable exits. - for (auto &BTCI : BackedgeTakenCounts) - BTCI.second.clear(); - for (auto &BTCI : PredicatedBackedgeTakenCounts) - BTCI.second.clear(); + BackedgeTakenCounts.clear(); + PredicatedBackedgeTakenCounts.clear(); assert(PendingLoopPredicates.empty() && "isImpliedCond garbage"); assert(PendingPhiRanges.empty() && "getRangeRef garbage"); @@ -12648,10 +12629,9 @@ ScalarEvolution::forgetMemoizedResults(const SCEV *S) { [S, this](DenseMap &Map) { for (auto I = Map.begin(), E = Map.end(); I != E;) { BackedgeTakenInfo &BEInfo = I->second; - if (BEInfo.hasOperand(S, this)) { - BEInfo.clear(); + if (BEInfo.hasOperand(S, this)) Map.erase(I++); - } else + else ++I; } }; -- 2.7.4