@@ -6353,61 +6353,66 @@ ScalarEvolution::getBackedgeTakenInfo(const Loop *L) {
6353
6353
void ScalarEvolution::forgetLoop (const Loop *L) {
6354
6354
// Drop any stored trip count value.
6355
6355
auto RemoveLoopFromBackedgeMap =
6356
- [L ](DenseMap<const Loop *, BackedgeTakenInfo> &Map) {
6356
+ [](DenseMap<const Loop *, BackedgeTakenInfo> &Map, const Loop *L ) {
6357
6357
auto BTCPos = Map.find (L);
6358
6358
if (BTCPos != Map.end ()) {
6359
6359
BTCPos->second .clear ();
6360
6360
Map.erase (BTCPos);
6361
6361
}
6362
6362
};
6363
6363
6364
- RemoveLoopFromBackedgeMap (BackedgeTakenCounts);
6365
- RemoveLoopFromBackedgeMap (PredicatedBackedgeTakenCounts);
6364
+ SmallVector<const Loop *, 16 > LoopWorklist (1 , L);
6365
+ SmallVector<Instruction *, 32 > Worklist;
6366
+ SmallPtrSet<Instruction *, 16 > Visited;
6366
6367
6367
- // Drop information about predicated SCEV rewrites for this loop.
6368
- for (auto I = PredicatedSCEVRewrites.begin ();
6369
- I != PredicatedSCEVRewrites.end ();) {
6370
- std::pair<const SCEV *, const Loop *> Entry = I->first ;
6371
- if (Entry.second == L)
6372
- PredicatedSCEVRewrites.erase (I++);
6373
- else
6374
- ++I;
6375
- }
6368
+ // Iterate over all the loops and sub-loops to drop SCEV information.
6369
+ while (!LoopWorklist.empty ()) {
6370
+ auto *CurrL = LoopWorklist.pop_back_val ();
6376
6371
6377
- // Drop information about expressions based on loop-header PHIs.
6378
- SmallVector<Instruction *, 16 > Worklist;
6379
- PushLoopPHIs (L, Worklist);
6380
-
6381
- SmallPtrSet<Instruction *, 8 > Visited;
6382
- while (!Worklist.empty ()) {
6383
- Instruction *I = Worklist.pop_back_val ();
6384
- if (!Visited.insert (I).second )
6385
- continue ;
6372
+ RemoveLoopFromBackedgeMap (BackedgeTakenCounts, CurrL);
6373
+ RemoveLoopFromBackedgeMap (PredicatedBackedgeTakenCounts, CurrL);
6386
6374
6387
- ValueExprMapType::iterator It =
6388
- ValueExprMap.find_as (static_cast <Value *>(I));
6389
- if (It != ValueExprMap.end ()) {
6390
- eraseValueFromMap (It->first );
6391
- forgetMemoizedResults (It->second );
6392
- if (PHINode *PN = dyn_cast<PHINode>(I))
6393
- ConstantEvolutionLoopExitValue.erase (PN);
6375
+ // Drop information about predicated SCEV rewrites for this loop.
6376
+ for (auto I = PredicatedSCEVRewrites.begin ();
6377
+ I != PredicatedSCEVRewrites.end ();) {
6378
+ std::pair<const SCEV *, const Loop *> Entry = I->first ;
6379
+ if (Entry.second == CurrL)
6380
+ PredicatedSCEVRewrites.erase (I++);
6381
+ else
6382
+ ++I;
6394
6383
}
6395
6384
6396
- PushDefUseChildren (I, Worklist);
6397
- }
6385
+ // Drop information about expressions based on loop-header PHIs.
6386
+ PushLoopPHIs (CurrL, Worklist);
6398
6387
6399
- for (auto I = ExitLimits.begin (); I != ExitLimits.end (); ++I) {
6400
- auto &Query = I->first ;
6401
- if (Query.L == L)
6402
- ExitLimits.erase (I);
6403
- }
6388
+ while (!Worklist.empty ()) {
6389
+ Instruction *I = Worklist.pop_back_val ();
6390
+ if (!Visited.insert (I).second )
6391
+ continue ;
6404
6392
6405
- // Forget all contained loops too, to avoid dangling entries in the
6406
- // ValuesAtScopes map.
6407
- for (Loop *I : *L)
6408
- forgetLoop (I);
6393
+ ValueExprMapType::iterator It =
6394
+ ValueExprMap.find_as (static_cast <Value *>(I));
6395
+ if (It != ValueExprMap.end ()) {
6396
+ eraseValueFromMap (It->first );
6397
+ forgetMemoizedResults (It->second );
6398
+ if (PHINode *PN = dyn_cast<PHINode>(I))
6399
+ ConstantEvolutionLoopExitValue.erase (PN);
6400
+ }
6401
+
6402
+ PushDefUseChildren (I, Worklist);
6403
+ }
6409
6404
6410
- LoopPropertiesCache.erase (L);
6405
+ for (auto I = ExitLimits.begin (); I != ExitLimits.end (); ++I) {
6406
+ auto &Query = I->first ;
6407
+ if (Query.L == CurrL)
6408
+ ExitLimits.erase (I);
6409
+ }
6410
+
6411
+ LoopPropertiesCache.erase (CurrL);
6412
+ // Forget all contained loops too, to avoid dangling entries in the
6413
+ // ValuesAtScopes map.
6414
+ LoopWorklist.append (CurrL->begin (), CurrL->end ());
6415
+ }
6411
6416
}
6412
6417
6413
6418
void ScalarEvolution::forgetValue (Value *V) {
0 commit comments