diff options
author | Justin Lebar <jlebar@google.com> | 2016-07-27 22:33:36 +0000 |
---|---|---|
committer | Justin Lebar <jlebar@google.com> | 2016-07-27 22:33:36 +0000 |
commit | 58b377e87d8cc1682a68284a3b253cdcd2bb0b25 (patch) | |
tree | d02ab08512c638906d04869527144e961575e3f9 /llvm/lib/Analysis/LazyValueInfo.cpp | |
parent | ed4f172c00baee0127c14df55364ae8a80b05a8e (diff) | |
download | llvm-58b377e87d8cc1682a68284a3b253cdcd2bb0b25.zip llvm-58b377e87d8cc1682a68284a3b253cdcd2bb0b25.tar.gz llvm-58b377e87d8cc1682a68284a3b253cdcd2bb0b25.tar.bz2 |
[LVI] Use DenseMap::find_as in LazyValueInfo.
Summary:
This lets us avoid creating and destroying a CallbackVH every time we
check the cache.
This is good for a 2% e2e speedup when compiling one of the large Eigen
tests at -O3.
FTR, I tried making the ValueCache hashtable one-level -- i.e., mapping
a pair (Value*, BasicBlock*) to a lattice value, and that didn't seem to
provide any additional improvement. Saving a word in LVILatticeVal by
merging the Tag and Val fields also didn't yield a speedup.
Reviewers: reames
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D21951
llvm-svn: 276926
Diffstat (limited to 'llvm/lib/Analysis/LazyValueInfo.cpp')
-rw-r--r-- | llvm/lib/Analysis/LazyValueInfo.cpp | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp index 8b896af..101b15d 100644 --- a/llvm/lib/Analysis/LazyValueInfo.cpp +++ b/llvm/lib/Analysis/LazyValueInfo.cpp @@ -366,6 +366,9 @@ namespace { /// A callback value handle updates the cache when values are erased. class LazyValueInfoCache; struct LVIValueHandle final : public CallbackVH { + // Needs to access getValPtr(), which is protected. + friend struct DenseMapInfo<LVIValueHandle>; + LazyValueInfoCache *Parent; LVIValueHandle(Value *V, LazyValueInfoCache *P) @@ -376,7 +379,7 @@ namespace { deleted(); } }; -} +} // end anonymous namespace namespace { /// This is the cache kept by LazyValueInfo which @@ -387,12 +390,15 @@ namespace { /// entries, allowing us to do a lookup with a binary search. /// Over-defined lattice values are recorded in OverDefinedCache to reduce /// memory overhead. - typedef SmallDenseMap<AssertingVH<BasicBlock>, LVILatticeVal, 4> - ValueCacheEntryTy; + struct ValueCacheEntryTy { + ValueCacheEntryTy(Value *V, LazyValueInfoCache *P) : Handle(V, P) {} + LVIValueHandle Handle; + SmallDenseMap<AssertingVH<BasicBlock>, LVILatticeVal, 4> BlockVals; + }; /// This is all of the cached information for all values, /// mapped from Value* to key information. - std::map<LVIValueHandle, ValueCacheEntryTy> ValueCache; + DenseMap<Value *, std::unique_ptr<ValueCacheEntryTy>> ValueCache; /// This tracks, on a per-block basis, the set of values that are /// over-defined at the end of that block. @@ -437,8 +443,15 @@ namespace { // overhead. if (Result.isOverdefined()) OverDefinedCache[BB].insert(Val); - else - lookup(Val)[BB] = Result; + else { + auto It = ValueCache.find_as(Val); + if (It == ValueCache.end()) { + ValueCache[Val] = make_unique<ValueCacheEntryTy>(Val, this); + It = ValueCache.find_as(Val); + assert(It != ValueCache.end() && "Val was just added to the map!"); + } + It->second->BlockVals[BB] = Result; + } } LVILatticeVal getBlockValue(Value *Val, BasicBlock *BB); @@ -463,10 +476,6 @@ namespace { void solve(); - ValueCacheEntryTy &lookup(Value *V) { - return ValueCache[LVIValueHandle(V, this)]; - } - bool isOverdefined(Value *V, BasicBlock *BB) const { auto ODI = OverDefinedCache.find(BB); @@ -480,19 +489,24 @@ namespace { if (isOverdefined(V, BB)) return true; - LVIValueHandle ValHandle(V, this); - auto I = ValueCache.find(ValHandle); + auto I = ValueCache.find_as(V); if (I == ValueCache.end()) return false; - return I->second.count(BB); + return I->second->BlockVals.count(BB); } LVILatticeVal getCachedValueInfo(Value *V, BasicBlock *BB) { if (isOverdefined(V, BB)) return LVILatticeVal::getOverdefined(); - return lookup(V)[BB]; + auto I = ValueCache.find_as(V); + if (I == ValueCache.end()) + return LVILatticeVal(); + auto BBI = I->second->BlockVals.find(BB); + if (BBI == I->second->BlockVals.end()) + return LVILatticeVal(); + return BBI->second; } public: @@ -561,7 +575,7 @@ void LazyValueInfoCache::eraseBlock(BasicBlock *BB) { OverDefinedCache.erase(ODI); for (auto &I : ValueCache) - I.second.erase(BB); + I.second->BlockVals.erase(BB); } void LazyValueInfoCache::solve() { |