Add a "seen blocks" cache to LVI to avoid a linear scan over the whole cache just to remove no blocks from the maps.

-15% on ARMDisassembler.cpp (Release build).  It's not that great to add another
layer of caching to the caching-heavy LVI but I don't see a better way.

llvm-svn: 145770
This commit is contained in:
Benjamin Kramer 2011-12-03 15:16:45 +00:00
parent df88864273
commit 3664708378
1 changed files with 13 additions and 1 deletions

View File

@ -372,6 +372,10 @@ namespace {
typedef std::pair<AssertingVH<BasicBlock>, Value*> OverDefinedPairTy; typedef std::pair<AssertingVH<BasicBlock>, Value*> OverDefinedPairTy;
DenseSet<OverDefinedPairTy> OverDefinedCache; DenseSet<OverDefinedPairTy> OverDefinedCache;
/// SeenBlocks - Keep track of all blocks that we have ever seen, so we
/// don't spend time removing unused blocks from our caches.
DenseSet<AssertingVH<BasicBlock> > SeenBlocks;
/// BlockValueStack - This stack holds the state of the value solver /// BlockValueStack - This stack holds the state of the value solver
/// during a query. It basically emulates the callstack of the naive /// during a query. It basically emulates the callstack of the naive
/// recursive value lookup process. /// recursive value lookup process.
@ -470,6 +474,12 @@ void LVIValueHandle::deleted() {
} }
void LazyValueInfoCache::eraseBlock(BasicBlock *BB) { void LazyValueInfoCache::eraseBlock(BasicBlock *BB) {
// Shortcut if we have never seen this block.
DenseSet<AssertingVH<BasicBlock> >::iterator I = SeenBlocks.find(BB);
if (I == SeenBlocks.end())
return;
SeenBlocks.erase(I);
SmallVector<OverDefinedPairTy, 4> ToErase; SmallVector<OverDefinedPairTy, 4> ToErase;
for (DenseSet<OverDefinedPairTy>::iterator I = OverDefinedCache.begin(), for (DenseSet<OverDefinedPairTy>::iterator I = OverDefinedCache.begin(),
E = OverDefinedCache.end(); I != E; ++I) { E = OverDefinedCache.end(); I != E; ++I) {
@ -509,6 +519,7 @@ LVILatticeVal LazyValueInfoCache::getBlockValue(Value *Val, BasicBlock *BB) {
if (Constant *VC = dyn_cast<Constant>(Val)) if (Constant *VC = dyn_cast<Constant>(Val))
return LVILatticeVal::get(VC); return LVILatticeVal::get(VC);
SeenBlocks.insert(BB);
return lookup(Val)[BB]; return lookup(Val)[BB];
} }
@ -517,6 +528,7 @@ bool LazyValueInfoCache::solveBlockValue(Value *Val, BasicBlock *BB) {
return true; return true;
ValueCacheEntryTy &Cache = lookup(Val); ValueCacheEntryTy &Cache = lookup(Val);
SeenBlocks.insert(BB);
LVILatticeVal &BBLV = Cache[BB]; LVILatticeVal &BBLV = Cache[BB];
// OverDefinedCacheUpdater is a helper object that will update // OverDefinedCacheUpdater is a helper object that will update