}
/// Push users of the given Instruction onto the given Worklist.
-static void
-PushDefUseChildren(Instruction *I,
- SmallVectorImpl<Instruction *> &Worklist) {
+static void PushDefUseChildren(Instruction *I,
+ SmallVectorImpl<Instruction *> &Worklist,
+ SmallPtrSetImpl<Instruction *> &Visited) {
// Push the def-use children onto the Worklist stack.
- for (User *U : I->users())
- Worklist.push_back(cast<Instruction>(U));
+ for (User *U : I->users()) {
+ auto *UserInsn = cast<Instruction>(U);
+ if (Visited.insert(UserInsn).second)
+ Worklist.push_back(UserInsn);
+ }
}
void ScalarEvolution::forgetSymbolicName(Instruction *PN, const SCEV *SymName) {
SmallVector<Instruction *, 16> Worklist;
- PushDefUseChildren(PN, Worklist);
-
SmallPtrSet<Instruction *, 8> Visited;
Visited.insert(PN);
+ Worklist.push_back(PN);
while (!Worklist.empty()) {
Instruction *I = Worklist.pop_back_val();
- if (!Visited.insert(I).second)
- continue;
auto It = ValueExprMap.find_as(static_cast<Value *>(I));
if (It != ValueExprMap.end()) {
}
}
- PushDefUseChildren(I, Worklist);
+ PushDefUseChildren(I, Worklist, Visited);
}
}
}
/// Push PHI nodes in the header of the given loop onto the given Worklist.
-static void
-PushLoopPHIs(const Loop *L, SmallVectorImpl<Instruction *> &Worklist) {
+static void PushLoopPHIs(const Loop *L,
+ SmallVectorImpl<Instruction *> &Worklist,
+ SmallPtrSetImpl<Instruction *> &Visited) {
BasicBlock *Header = L->getHeader();
// Push all Loop-header PHIs onto the Worklist stack.
for (PHINode &PN : Header->phis())
- Worklist.push_back(&PN);
+ if (Visited.insert(&PN).second)
+ Worklist.push_back(&PN);
}
const ScalarEvolution::BackedgeTakenInfo &
// it handles SCEVUnknown PHI nodes specially.
if (Result.hasAnyInfo()) {
SmallVector<Instruction *, 16> Worklist;
- PushLoopPHIs(L, Worklist);
-
SmallPtrSet<Instruction *, 8> Discovered;
+ PushLoopPHIs(L, Worklist, Discovered);
while (!Worklist.empty()) {
Instruction *I = Worklist.pop_back_val();
}
// Drop information about expressions based on loop-header PHIs.
- PushLoopPHIs(CurrL, Worklist);
+ PushLoopPHIs(CurrL, Worklist, Visited);
while (!Worklist.empty()) {
Instruction *I = Worklist.pop_back_val();
- if (!Visited.insert(I).second)
- continue;
ValueExprMapType::iterator It =
ValueExprMap.find_as(static_cast<Value *>(I));
ConstantEvolutionLoopExitValue.erase(PN);
}
- PushDefUseChildren(I, Worklist);
+ PushDefUseChildren(I, Worklist, Visited);
}
LoopPropertiesCache.erase(CurrL);
// Drop information about expressions based on loop-header PHIs.
SmallVector<Instruction *, 16> Worklist;
+ SmallPtrSet<Instruction *, 8> Visited;
Worklist.push_back(I);
+ Visited.insert(I);
- SmallPtrSet<Instruction *, 8> Visited;
while (!Worklist.empty()) {
I = Worklist.pop_back_val();
- if (!Visited.insert(I).second)
- continue;
-
ValueExprMapType::iterator It =
ValueExprMap.find_as(static_cast<Value *>(I));
if (It != ValueExprMap.end()) {
ConstantEvolutionLoopExitValue.erase(PN);
}
- PushDefUseChildren(I, Worklist);
+ PushDefUseChildren(I, Worklist, Visited);
}
}