[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 00:42:40 PST 2023
fhahn created this revision.
fhahn added reviewers: mkazantsev, nikic, reames.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
fhahn requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This allows for easier updating of common code in follow-on patches.
Repository:
rG LLVM Github Monorepo
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
@@ -8435,6 +8435,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);
@@ -8468,21 +8487,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
@@ -8506,20 +8511,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
@@ -2039,6 +2039,12 @@
/// Helper for forgetMemoizedResults.
void forgetMemoizedResultsImpl(const SCEV *S);
+ /// Iterate over instructions in \p Worlist 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.500684.patch
Type: text/x-patch
Size: 3237 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230227/d69d17c4/attachment.bin>
More information about the llvm-commits
mailing list