[PATCH] [ScalarEvolution] Change data structure to memorize computed result
Wan, Xiaofei
xiaofei.wan at intel.com
Mon Nov 11 06:45:09 PST 2013
Hashing on a pointer pair
Hi atrick,
http://llvm-reviews.chandlerc.com/D2117
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D2117?vs=5393&id=5443#toc
Files:
include/llvm/Analysis/ScalarEvolution.h
lib/Analysis/ScalarEvolution.cpp
Index: include/llvm/Analysis/ScalarEvolution.h
===================================================================
--- include/llvm/Analysis/ScalarEvolution.h
+++ include/llvm/Analysis/ScalarEvolution.h
@@ -360,19 +360,16 @@
/// ValuesAtScopes - This map contains entries for all the expressions
/// that we attempt to compute getSCEVAtScope information for, which can
/// be expensive in extreme cases.
- DenseMap<const SCEV *,
- std::map<const Loop *, const SCEV *> > ValuesAtScopes;
+ DenseMap<std::pair<const SCEV *, const Loop *>, const SCEV *> ValuesAtScopes;
/// LoopDispositions - Memoized computeLoopDisposition results.
- DenseMap<const SCEV *,
- std::map<const Loop *, LoopDisposition> > LoopDispositions;
+ DenseMap<std::pair<const SCEV *, const Loop *>, LoopDisposition> LoopDispositions;
/// computeLoopDisposition - Compute a LoopDisposition value.
LoopDisposition computeLoopDisposition(const SCEV *S, const Loop *L);
/// BlockDispositions - Memoized computeBlockDisposition results.
- DenseMap<const SCEV *,
- std::map<const BasicBlock *, BlockDisposition> > BlockDispositions;
+ DenseMap<std::pair<const SCEV *, const BasicBlock *>, BlockDisposition> BlockDispositions;
/// computeBlockDisposition - Compute a BlockDisposition value.
BlockDisposition computeBlockDisposition(const SCEV *S, const BasicBlock *BB);
Index: lib/Analysis/ScalarEvolution.cpp
===================================================================
--- lib/Analysis/ScalarEvolution.cpp
+++ lib/Analysis/ScalarEvolution.cpp
@@ -5059,15 +5059,13 @@
/// original value V is returned.
const SCEV *ScalarEvolution::getSCEVAtScope(const SCEV *V, const Loop *L) {
// Check to see if we've folded this expression at this loop before.
- std::map<const Loop *, const SCEV *> &Values = ValuesAtScopes[V];
- std::pair<std::map<const Loop *, const SCEV *>::iterator, bool> Pair =
- Values.insert(std::make_pair(L, static_cast<const SCEV *>(0)));
- if (!Pair.second)
- return Pair.first->second ? Pair.first->second : V;
+ DenseMap<std::pair<const SCEV *, const Loop *>, const SCEV *>::iterator Pair = ValuesAtScopes.find(std::make_pair(V, L));
+ if (Pair != ValuesAtScopes.end())
+ return Pair->second ? Pair->second : V;
// Otherwise compute it.
const SCEV *C = computeSCEVAtScope(V, L);
- ValuesAtScopes[V][L] = C;
+ ValuesAtScopes[std::make_pair(V, L)] = C;
return C;
}
@@ -6727,7 +6725,7 @@
//===----------------------------------------------------------------------===//
ScalarEvolution::ScalarEvolution()
- : FunctionPass(ID), FirstUnknown(0) {
+ : FunctionPass(ID), ValuesAtScopes(64), LoopDispositions(128), BlockDispositions(128), FirstUnknown(0) {
initializeScalarEvolutionPass(*PassRegistry::getPassRegistry());
}
@@ -6865,14 +6863,12 @@
ScalarEvolution::LoopDisposition
ScalarEvolution::getLoopDisposition(const SCEV *S, const Loop *L) {
- std::map<const Loop *, LoopDisposition> &Values = LoopDispositions[S];
- std::pair<std::map<const Loop *, LoopDisposition>::iterator, bool> Pair =
- Values.insert(std::make_pair(L, LoopVariant));
- if (!Pair.second)
- return Pair.first->second;
+ DenseMap<std::pair<const SCEV *, const Loop *>, LoopDisposition>::iterator Pair = LoopDispositions.find(std::make_pair(S, L));
+ if (Pair != LoopDispositions.end())
+ return Pair->second;
LoopDisposition D = computeLoopDisposition(S, L);
- return LoopDispositions[S][L] = D;
+ return LoopDispositions[std::make_pair(S, L)] = D;
}
ScalarEvolution::LoopDisposition
@@ -6964,14 +6960,12 @@
ScalarEvolution::BlockDisposition
ScalarEvolution::getBlockDisposition(const SCEV *S, const BasicBlock *BB) {
- std::map<const BasicBlock *, BlockDisposition> &Values = BlockDispositions[S];
- std::pair<std::map<const BasicBlock *, BlockDisposition>::iterator, bool>
- Pair = Values.insert(std::make_pair(BB, DoesNotDominateBlock));
- if (!Pair.second)
- return Pair.first->second;
+ DenseMap<std::pair<const SCEV *, const BasicBlock *>, BlockDisposition>::iterator Pair = BlockDispositions.find(std::make_pair(S, BB));
+ if (Pair != BlockDispositions.end())
+ return Pair->second;
BlockDisposition D = computeBlockDisposition(S, BB);
- return BlockDispositions[S][BB] = D;
+ return BlockDispositions[std::make_pair(S, BB)] = D;
}
ScalarEvolution::BlockDisposition
@@ -7070,9 +7064,6 @@
}
void ScalarEvolution::forgetMemoizedResults(const SCEV *S) {
- ValuesAtScopes.erase(S);
- LoopDispositions.erase(S);
- BlockDispositions.erase(S);
UnsignedRanges.erase(S);
SignedRanges.erase(S);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2117.2.patch
Type: text/x-patch
Size: 4674 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131111/d6a0a446/attachment.bin>
More information about the llvm-commits
mailing list