fix compile-time regression report by Joerg Sonnenberger:

cache result of Size/OffsetVisitor to speedup analysis of PHI nodes

llvm-svn: 172363
This commit is contained in:
Nuno Lopes 2013-01-13 18:02:57 +00:00
parent dc81f51d37
commit f4ddc9c002
2 changed files with 13 additions and 9 deletions

View File

@ -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);

View File

@ -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();
// 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 Ret;
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))