+void LazyValueInfoCache::threadEdge(BasicBlock *PredBB, BasicBlock *OldSucc,
+ BasicBlock *NewSucc) {
+ // When an edge in the graph has been threaded, values that we could not
+ // determine a value for before (i.e. were marked overdefined) may be possible
+ // to solve now. We do NOT try to proactively update these values. Instead,
+ // we clear their entries from the cache, and allow lazy updating to recompute
+ // them when needed.
+
+ // The updating process is fairly simple: we need to dropped cached info
+ // for all values that were marked overdefined in OldSucc, and for those same
+ // values in any successor of OldSucc (except NewSucc) in which they were
+ // also marked overdefined.
+ std::vector<BasicBlock*> worklist;
+ worklist.push_back(OldSucc);
+
+ std::set<Value*> ClearSet = OverDefinedCache[OldSucc];
+ LVILatticeVal OverDef;
+ OverDef.markOverdefined();
+
+ // Use a worklist to perform a depth-first search of OldSucc's successors.
+ // NOTE: We do not need a visited list since any blocks we have already
+ // visited will have had their overdefined markers cleared already, and we
+ // thus won't loop to their successors.
+ while (!worklist.empty()) {
+ BasicBlock *ToUpdate = worklist.back();
+ worklist.pop_back();
+
+ // Skip blocks only accessible through NewSucc.
+ if (ToUpdate == NewSucc) continue;
+
+ bool changed = false;
+ std::set<Value*> &CurrentSet = OverDefinedCache[ToUpdate];
+ for (std::set<Value*>::iterator I = ClearSet.begin(),E = ClearSet.end();
+ I != E; ++I) {
+ // If a value was marked overdefined in OldSucc, and is here too...
+ if (CurrentSet.count(*I)) {
+ // Remove it from the caches.
+ ValueCacheEntryTy &Entry = ValueCache[*I];
+ ValueCacheEntryTy::iterator CI =
+ std::lower_bound(Entry.begin(), Entry.end(),
+ std::make_pair(ToUpdate, OverDef),
+ BlockCacheEntryComparator());
+ assert(CI != Entry.end() && "Couldn't find entry to update?");
+ Entry.erase(CI);
+
+ CurrentSet.erase(*I);
+
+ // If we removed anything, then we potentially need to update
+ // blocks successors too.
+ changed = true;
+ }
+ }
+
+ if (!changed) continue;
+
+ worklist.insert(worklist.end(), succ_begin(ToUpdate), succ_end(ToUpdate));
+ }
+}
+