diff options
-rw-r--r-- | include/llvm/Analysis/MemoryBuiltins.h | 4 | ||||
-rw-r--r-- | lib/Analysis/MemoryBuiltins.cpp | 20 |
2 files changed, 14 insertions, 10 deletions
diff --git a/include/llvm/Analysis/MemoryBuiltins.h b/include/llvm/Analysis/MemoryBuiltins.h index f2c564f..2a9cd75 100644 --- a/include/llvm/Analysis/MemoryBuiltins.h +++ b/include/llvm/Analysis/MemoryBuiltins.h @@ -153,12 +153,14 @@ typedef std::pair<APInt, APInt> SizeOffsetType; class ObjectSizeOffsetVisitor : public InstVisitor<ObjectSizeOffsetVisitor, SizeOffsetType> { + typedef DenseMap<const Value*, SizeOffsetType> CacheMapTy; + const DataLayout *TD; const TargetLibraryInfo *TLI; bool RoundToAlign; unsigned IntTyBits; APInt Zero; - SmallPtrSet<Value*, 8> SeenInsts; + CacheMapTy CacheMap; APInt align(APInt Size, uint64_t Align); 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)) |