public:
/// BlockCacheEntryTy - This is a computed lattice value at the end of the
/// specified basic block for a Value* that depends on context.
- typedef std::pair<BasicBlock*, LVILatticeVal> BlockCacheEntryTy;
+ typedef std::pair<AssertingVH<BasicBlock>, LVILatticeVal> BlockCacheEntryTy;
/// ValueCacheEntryTy - This is all of the cached block information for
/// exactly one Value*. The entries are sorted by the BasicBlock* of the
/// entries, allowing us to do a lookup with a binary search.
- typedef std::map<BasicBlock*, LVILatticeVal> ValueCacheEntryTy;
+ typedef std::map<AssertingVH<BasicBlock>, LVILatticeVal> ValueCacheEntryTy;
private:
/// LVIValueHandle - A callback value handle update the cache when
/// OverDefinedCache - This tracks, on a per-block basis, the set of
/// values that are over-defined at the end of that block. This is required
/// for cache updating.
- std::set<std::pair<BasicBlock*, Value*> > OverDefinedCache;
+ std::set<std::pair<AssertingVH<BasicBlock>, Value*> > OverDefinedCache;
public:
/// edge from PredBB to OldSucc has been threaded to be from PredBB to
/// NewSucc.
void threadEdge(BasicBlock *PredBB,BasicBlock *OldSucc,BasicBlock *NewSucc);
+
+ /// eraseBlock - This is part of the update interface to inform the cache
+ /// that a block has been deleted.
+ void eraseBlock(BasicBlock *BB);
+
+ /// clear - Empty the cache.
+ void clear() {
+ ValueCache.clear();
+ OverDefinedCache.clear();
+ }
};
} // end anonymous namespace
ValueCacheEntryTy &Cache;
/// This tracks, for each block, what values are overdefined.
- std::set<std::pair<BasicBlock*, Value*> > &OverDefinedCache;
+ std::set<std::pair<AssertingVH<BasicBlock>, Value*> > &OverDefinedCache;
/// NewBlocks - This is a mapping of the new BasicBlocks which have been
/// added to cache but that are not in sorted order.
LVIQuery(Value *V, LazyValueInfoCache &P,
ValueCacheEntryTy &VC,
- std::set<std::pair<BasicBlock*, Value*> > &ODC)
+ std::set<std::pair<AssertingVH<BasicBlock>, Value*> > &ODC)
: Val(V), Parent(P), Cache(VC), OverDefinedCache(ODC) {
}
} // end anonymous namespace
void LazyValueInfoCache::LVIValueHandle::deleted() {
- for (std::set<std::pair<BasicBlock*, Value*> >::iterator
+ for (std::set<std::pair<AssertingVH<BasicBlock>, Value*> >::iterator
I = Parent->OverDefinedCache.begin(),
E = Parent->OverDefinedCache.end();
I != E; ) {
- std::set<std::pair<BasicBlock*, Value*> >::iterator tmp = I;
+ std::set<std::pair<AssertingVH<BasicBlock>, Value*> >::iterator tmp = I;
++I;
if (tmp->second == getValPtr())
Parent->OverDefinedCache.erase(tmp);
Parent->ValueCache.erase(*this);
}
+void LazyValueInfoCache::eraseBlock(BasicBlock *BB) {
+ for (std::set<std::pair<AssertingVH<BasicBlock>, Value*> >::iterator
+ I = OverDefinedCache.begin(), E = OverDefinedCache.end(); I != E; ) {
+ std::set<std::pair<AssertingVH<BasicBlock>, Value*> >::iterator tmp = I;
+ ++I;
+ if (tmp->first == BB)
+ OverDefinedCache.erase(tmp);
+ }
+
+ for (std::map<LVIValueHandle, ValueCacheEntryTy>::iterator
+ I = ValueCache.begin(), E = ValueCache.end(); I != E; ++I)
+ I->second.erase(BB);
+}
/// getCachedEntryForBlock - See if we already have a value for this block. If
/// so, return it, otherwise create a new entry in the Cache map to use.
// Return the merged value, which is more precise than 'overdefined'.
assert(!Result.isOverdefined());
- Cache[BB] = Result;
-
+ return Cache[BB] = Result;
} else {
}
-
- DEBUG(dbgs() << " compute BB '" << BB->getName()
- << "' - overdefined because inst def found.\n");
LVILatticeVal Result;
Result.markOverdefined();
worklist.push_back(OldSucc);
DenseSet<Value*> ClearSet;
- for (std::set<std::pair<BasicBlock*, Value*> >::iterator
+ for (std::set<std::pair<AssertingVH<BasicBlock>, Value*> >::iterator
I = OverDefinedCache.begin(), E = OverDefinedCache.end(); I != E; ++I) {
if (I->first == OldSucc)
ClearSet.insert(I->second);
for (DenseSet<Value*>::iterator I = ClearSet.begin(),E = ClearSet.end();
I != E; ++I) {
// If a value was marked overdefined in OldSucc, and is here too...
- std::set<std::pair<BasicBlock*, Value*> >::iterator OI =
+ std::set<std::pair<AssertingVH<BasicBlock>, Value*> >::iterator OI =
OverDefinedCache.find(std::make_pair(ToUpdate, *I));
if (OI == OverDefinedCache.end()) continue;
// LazyValueInfo Impl
//===----------------------------------------------------------------------===//
-bool LazyValueInfo::runOnFunction(Function &F) {
- TD = getAnalysisIfAvailable<TargetData>();
- // Fully lazy.
- return false;
-}
-
/// getCache - This lazily constructs the LazyValueInfoCache.
static LazyValueInfoCache &getCache(void *&PImpl) {
if (!PImpl)
return *static_cast<LazyValueInfoCache*>(PImpl);
}
+bool LazyValueInfo::runOnFunction(Function &F) {
+ if (PImpl)
+ getCache(PImpl).clear();
+
+ TD = getAnalysisIfAvailable<TargetData>();
+ // Fully lazy.
+ return false;
+}
+
void LazyValueInfo::releaseMemory() {
// If the cache was allocated, free it.
if (PImpl) {
void LazyValueInfo::threadEdge(BasicBlock *PredBB, BasicBlock *OldSucc,
BasicBlock* NewSucc) {
- getCache(PImpl).threadEdge(PredBB, OldSucc, NewSucc);
+ if (PImpl) getCache(PImpl).threadEdge(PredBB, OldSucc, NewSucc);
+}
+
+void LazyValueInfo::eraseBlock(BasicBlock *BB) {
+ if (PImpl) getCache(PImpl).eraseBlock(BB);
}