diff options
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)) |