[SCEV][NFC] Apply mass forgetMemoizedResults queries where possible

When forgetting multiple SCEVs, rather than doing this one by one, we can
instead use mass updates. We plan to make them more efficient than they
are now, potentially improving compile time.

Differential Revision: https://reviews.llvm.org/D111602
Reviewed By: reames
This commit is contained in:
Max Kazantsev 2021-10-25 13:50:49 +07:00
parent a6096b7f9e
commit dbab339ea4
1 changed files with 14 additions and 6 deletions

View File

@ -4434,6 +4434,7 @@ static void PushDefUseChildren(Instruction *I,
void ScalarEvolution::forgetSymbolicName(Instruction *PN, const SCEV *SymName) {
SmallVector<Instruction *, 16> Worklist;
SmallPtrSet<Instruction *, 8> Visited;
SmallVector<const SCEV *, 8> ToForget;
Visited.insert(PN);
Worklist.push_back(PN);
while (!Worklist.empty()) {
@ -4459,12 +4460,13 @@ void ScalarEvolution::forgetSymbolicName(Instruction *PN, const SCEV *SymName) {
!isa<SCEVUnknown>(Old) ||
(I != PN && Old == SymName)) {
eraseValueFromMap(It->first);
forgetMemoizedResults(Old);
ToForget.push_back(Old);
}
}
PushDefUseChildren(I, Worklist, Visited);
}
forgetMemoizedResults(ToForget);
}
namespace {
@ -7450,6 +7452,7 @@ ScalarEvolution::getBackedgeTakenInfo(const Loop *L) {
if (Result.hasAnyInfo()) {
SmallVector<Instruction *, 16> Worklist;
SmallPtrSet<Instruction *, 8> Discovered;
SmallVector<const SCEV *, 8> ToForget;
PushLoopPHIs(L, Worklist, Discovered);
while (!Worklist.empty()) {
Instruction *I = Worklist.pop_back_val();
@ -7467,7 +7470,7 @@ ScalarEvolution::getBackedgeTakenInfo(const Loop *L) {
// own when it gets to that point.
if (!isa<PHINode>(I) || !isa<SCEVUnknown>(Old)) {
eraseValueFromMap(It->first);
forgetMemoizedResults(Old);
ToForget.push_back(Old);
}
if (PHINode *PN = dyn_cast<PHINode>(I))
ConstantEvolutionLoopExitValue.erase(PN);
@ -7499,6 +7502,7 @@ ScalarEvolution::getBackedgeTakenInfo(const Loop *L) {
Worklist.push_back(I);
}
}
forgetMemoizedResults(ToForget);
}
// Re-lookup the insert position, since the call to
@ -7535,6 +7539,7 @@ void ScalarEvolution::forgetLoop(const Loop *L) {
SmallVector<const Loop *, 16> LoopWorklist(1, L);
SmallVector<Instruction *, 32> Worklist;
SmallPtrSet<Instruction *, 16> Visited;
SmallVector<const SCEV *, 16> ToForget;
// Iterate over all the loops and sub-loops to drop SCEV information.
while (!LoopWorklist.empty()) {
@ -7556,8 +7561,8 @@ void ScalarEvolution::forgetLoop(const Loop *L) {
auto LoopUsersItr = LoopUsers.find(CurrL);
if (LoopUsersItr != LoopUsers.end()) {
for (auto *S : LoopUsersItr->second)
forgetMemoizedResults(S);
ToForget.insert(ToForget.end(), LoopUsersItr->second.begin(),
LoopUsersItr->second.end());
LoopUsers.erase(LoopUsersItr);
}
@ -7571,7 +7576,7 @@ void ScalarEvolution::forgetLoop(const Loop *L) {
ValueExprMap.find_as(static_cast<Value *>(I));
if (It != ValueExprMap.end()) {
eraseValueFromMap(It->first);
forgetMemoizedResults(It->second);
ToForget.push_back(It->second);
if (PHINode *PN = dyn_cast<PHINode>(I))
ConstantEvolutionLoopExitValue.erase(PN);
}
@ -7584,6 +7589,7 @@ void ScalarEvolution::forgetLoop(const Loop *L) {
// ValuesAtScopes map.
LoopWorklist.append(CurrL->begin(), CurrL->end());
}
forgetMemoizedResults(ToForget);
}
void ScalarEvolution::forgetTopmostLoop(const Loop *L) {
@ -7599,6 +7605,7 @@ void ScalarEvolution::forgetValue(Value *V) {
// Drop information about expressions based on loop-header PHIs.
SmallVector<Instruction *, 16> Worklist;
SmallPtrSet<Instruction *, 8> Visited;
SmallVector<const SCEV *, 8> ToForget;
Worklist.push_back(I);
Visited.insert(I);
@ -7608,13 +7615,14 @@ void ScalarEvolution::forgetValue(Value *V) {
ValueExprMap.find_as(static_cast<Value *>(I));
if (It != ValueExprMap.end()) {
eraseValueFromMap(It->first);
forgetMemoizedResults(It->second);
ToForget.push_back(It->second);
if (PHINode *PN = dyn_cast<PHINode>(I))
ConstantEvolutionLoopExitValue.erase(PN);
}
PushDefUseChildren(I, Worklist, Visited);
}
forgetMemoizedResults(ToForget);
}
void ScalarEvolution::forgetLoopDispositions(const Loop *L) {