diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-04-29 23:24:44 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-04-29 23:24:44 +0000 |
commit | 4d0348b6c74d2710a3693bbfbcfc5fcb3bc132ee (patch) | |
tree | 3a3564e3748b4dc19c0e87a10784c572da17538f /lib/Analysis/BasicValueFactory.cpp | |
parent | aa847fe3c88ee5e8d180e48537c58b805d48d95d (diff) |
Add lval::ArrayOffset, which represent the locations of entries in an array.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@50453 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/BasicValueFactory.cpp')
-rw-r--r-- | lib/Analysis/BasicValueFactory.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/Analysis/BasicValueFactory.cpp b/lib/Analysis/BasicValueFactory.cpp index b0aa79e067..8d737a9472 100644 --- a/lib/Analysis/BasicValueFactory.cpp +++ b/lib/Analysis/BasicValueFactory.cpp @@ -19,6 +19,8 @@ using namespace clang; typedef std::pair<RVal, uintptr_t> RValData; +typedef std::pair<RVal, RVal> RValPair; + namespace llvm { template<> struct FoldingSetTrait<RValData> { @@ -27,11 +29,21 @@ template<> struct FoldingSetTrait<RValData> { ID.AddPointer( (void*) X.second); } }; + +template<> struct FoldingSetTrait<RValPair> { + static inline void Profile(const RValPair& X, llvm::FoldingSetNodeID& ID) { + X.first.Profile(ID); + X.second.Profile(ID); + } +}; } typedef llvm::FoldingSet<llvm::FoldingSetNodeWrapper<RValData> > PersistentRValsTy; +typedef llvm::FoldingSet<llvm::FoldingSetNodeWrapper<RValPair> > + PersistentRValPairsTy; + BasicValueFactory::~BasicValueFactory() { // Note that the dstor for the contents of APSIntSet will never be called, // so we iterate over the set and invoke the dstor for each APSInt. This @@ -40,6 +52,7 @@ BasicValueFactory::~BasicValueFactory() { I->getValue().~APSInt(); delete (PersistentRValsTy*) PersistentRVals; + delete (PersistentRValPairsTy*) PersistentRValPairs; } const llvm::APSInt& BasicValueFactory::getValue(const llvm::APSInt& X) { @@ -208,3 +221,29 @@ BasicValueFactory::getPersistentRValWithData(const RVal& V, uintptr_t Data) { return P->getValue(); } + +const std::pair<RVal, RVal>& +BasicValueFactory::getPersistentRValPair(const RVal& V1, const RVal& V2) { + + // Lazily create the folding set. + if (!PersistentRValPairs) PersistentRValPairs = new PersistentRValPairsTy(); + + llvm::FoldingSetNodeID ID; + void* InsertPos; + V1.Profile(ID); + V2.Profile(ID); + + PersistentRValPairsTy& Map = *((PersistentRValPairsTy*) PersistentRValPairs); + + typedef llvm::FoldingSetNodeWrapper<RValPair> FoldNodeTy; + FoldNodeTy* P = Map.FindNodeOrInsertPos(ID, InsertPos); + + if (!P) { + P = (FoldNodeTy*) BPAlloc.Allocate<FoldNodeTy>(); + new (P) FoldNodeTy(std::make_pair(V1, V2)); + Map.InsertNode(P, InsertPos); + } + + return P->getValue(); +} + |