[PATCH] D144847: [SCEV] Hoist common cleanup code to function. (NFC)
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 27 11:39:20 PST 2023
This revision was automatically updated to reflect the committed changes.
fhahn marked an inline comment as done.
Closed by commit rG2f3c748c45ff: [SCEV] Hoist common cleanup code to function. (NFC) (authored by fhahn).
Changed prior to commit:
https://reviews.llvm.org/D144847?vs=500684&id=500862#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D144847/new/
https://reviews.llvm.org/D144847
Files:
llvm/include/llvm/Analysis/ScalarEvolution.h
llvm/lib/Analysis/ScalarEvolution.cpp
Index: llvm/lib/Analysis/ScalarEvolution.cpp
===================================================================
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -8415,6 +8415,25 @@
FoldCache.clear();
FoldCacheUser.clear();
}
+void ScalarEvolution::visitAndClearUsers(
+ SmallVectorImpl<Instruction *> &Worklist,
+ SmallPtrSetImpl<Instruction *> &Visited,
+ SmallVectorImpl<const SCEV *> &ToForget) {
+ while (!Worklist.empty()) {
+ Instruction *I = Worklist.pop_back_val();
+
+ ValueExprMapType::iterator It =
+ ValueExprMap.find_as(static_cast<Value *>(I));
+ if (It != ValueExprMap.end()) {
+ eraseValueFromMap(It->first);
+ ToForget.push_back(It->second);
+ if (PHINode *PN = dyn_cast<PHINode>(I))
+ ConstantEvolutionLoopExitValue.erase(PN);
+ }
+
+ PushDefUseChildren(I, Worklist, Visited);
+ }
+}
void ScalarEvolution::forgetLoop(const Loop *L) {
SmallVector<const Loop *, 16> LoopWorklist(1, L);
@@ -8448,21 +8467,7 @@
// Drop information about expressions based on loop-header PHIs.
PushLoopPHIs(CurrL, Worklist, Visited);
-
- while (!Worklist.empty()) {
- Instruction *I = Worklist.pop_back_val();
-
- ValueExprMapType::iterator It =
- ValueExprMap.find_as(static_cast<Value *>(I));
- if (It != ValueExprMap.end()) {
- eraseValueFromMap(It->first);
- ToForget.push_back(It->second);
- if (PHINode *PN = dyn_cast<PHINode>(I))
- ConstantEvolutionLoopExitValue.erase(PN);
- }
-
- PushDefUseChildren(I, Worklist, Visited);
- }
+ visitAndClearUsers(Worklist, Visited, ToForget);
LoopPropertiesCache.erase(CurrL);
// Forget all contained loops too, to avoid dangling entries in the
@@ -8486,20 +8491,8 @@
SmallVector<const SCEV *, 8> ToForget;
Worklist.push_back(I);
Visited.insert(I);
+ visitAndClearUsers(Worklist, Visited, ToForget);
- while (!Worklist.empty()) {
- I = Worklist.pop_back_val();
- ValueExprMapType::iterator It =
- ValueExprMap.find_as(static_cast<Value *>(I));
- if (It != ValueExprMap.end()) {
- eraseValueFromMap(It->first);
- ToForget.push_back(It->second);
- if (PHINode *PN = dyn_cast<PHINode>(I))
- ConstantEvolutionLoopExitValue.erase(PN);
- }
-
- PushDefUseChildren(I, Worklist, Visited);
- }
forgetMemoizedResults(ToForget);
}
Index: llvm/include/llvm/Analysis/ScalarEvolution.h
===================================================================
--- llvm/include/llvm/Analysis/ScalarEvolution.h
+++ llvm/include/llvm/Analysis/ScalarEvolution.h
@@ -2037,6 +2037,12 @@
/// Helper for forgetMemoizedResults.
void forgetMemoizedResultsImpl(const SCEV *S);
+ /// Iterate over instructions in \p Worklist and their users. Erase entries
+ /// from ValueExprMap and collect SCEV expressions in \p ToForget
+ void visitAndClearUsers(SmallVectorImpl<Instruction *> &Worklist,
+ SmallPtrSetImpl<Instruction *> &Visited,
+ SmallVectorImpl<const SCEV *> &ToForget);
+
/// Return an existing SCEV for V if there is one, otherwise return nullptr.
const SCEV *getExistingSCEV(Value *V);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144847.500862.patch
Type: text/x-patch
Size: 3238 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230227/28ece7bf/attachment.bin>
More information about the llvm-commits
mailing list