diff options
author | Nuno Lopes <nunoplopes@sapo.pt> | 2013-01-13 18:02:57 +0000 |
---|---|---|
committer | Nuno Lopes <nunoplopes@sapo.pt> | 2013-01-13 18:02:57 +0000 |
commit | 29eb2cc00ca0bc4d218c6d034f90becfed999bcb (patch) | |
tree | 59d5c0e76548bc7b30e6f2e7cfc5b3a0996cc74b /lib/Analysis | |
parent | 135174deb8e1e46d87b0aa55ef8df43c3ac79a8d (diff) | |
download | external_llvm-29eb2cc00ca0bc4d218c6d034f90becfed999bcb.zip external_llvm-29eb2cc00ca0bc4d218c6d034f90becfed999bcb.tar.gz external_llvm-29eb2cc00ca0bc4d218c6d034f90becfed999bcb.tar.bz2 |
fix compile-time regression report by Joerg Sonnenberger:
cache result of Size/OffsetVisitor to speedup analysis of PHI nodes
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@172363 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r-- | lib/Analysis/MemoryBuiltins.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/Analysis/MemoryBuiltins.cpp b/lib/Analysis/MemoryBuiltins.cpp index f88affb..1d27a83 100644 --- a/lib/Analysis/MemoryBuiltins.cpp +++ b/lib/Analysis/MemoryBuiltins.cpp @@ -387,17 +387,19 @@ SizeOffsetType ObjectSizeOffsetVisitor::compute(Value *V) { V = V->stripPointerCasts(); if (isa<Instruction>(V) || isa<GEPOperator>(V)) { - // If we have already seen this instruction, bail out. - if (!SeenInsts.insert(V)) - return unknown(); - - SizeOffsetType Ret; + // return cached value or insert unknown in cache if size of V was not + // computed yet in order to avoid recursions in PHis + std::pair<CacheMapTy::iterator, bool> CacheVal = + CacheMap.insert(std::make_pair(V, unknown())); + if (!CacheVal.second) + return CacheVal.first->second; + + SizeOffsetType Result; if (GEPOperator *GEP = dyn_cast<GEPOperator>(V)) - Ret = visitGEPOperator(*GEP); + Result = visitGEPOperator(*GEP); else - Ret = visit(cast<Instruction>(*V)); - SeenInsts.erase(V); - return Ret; + Result = visit(cast<Instruction>(*V)); + return CacheMap[V] = Result; } if (Argument *A = dyn_cast<Argument>(V)) |