[llvm] cc58e89 - [SCEV] Simplify backedge count clearing (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sat May 1 08:51:47 PDT 2021
Author: Nikita Popov
Date: 2021-05-01T17:50:01+02:00
New Revision: cc58e8918b70d5698ec06c0b6e4c6e4c27971870
URL: https://github.com/llvm/llvm-project/commit/cc58e8918b70d5698ec06c0b6e4c6e4c27971870
DIFF: https://github.com/llvm/llvm-project/commit/cc58e8918b70d5698ec06c0b6e4c6e4c27971870.diff
LOG: [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.
Added:
Modified:
llvm/include/llvm/Analysis/ScalarEvolution.h
llvm/lib/Analysis/ScalarEvolution.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h
index 414baac3f9185..e84b7101bfdf7 100644
--- a/llvm/include/llvm/Analysis/ScalarEvolution.h
+++ b/llvm/include/llvm/Analysis/ScalarEvolution.h
@@ -1461,9 +1461,6 @@ class ScalarEvolution {
/// 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 f224ab29d9429..4005597de792b 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<const Loop *, BackedgeTakenInfo> &Map, const Loop *L) {
- auto BTCPos = Map.find(L);
- if (BTCPos != Map.end()) {
- BTCPos->second.clear();
- Map.erase(BTCPos);
- }
- };
-
SmallVector<const Loop *, 16> LoopWorklist(1, L);
SmallVector<Instruction *, 32> Worklist;
SmallPtrSet<Instruction *, 16> 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<const Loop *, BackedgeTakenInfo> &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;
}
};
More information about the llvm-commits
mailing list