aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/BasicValueFactory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Analysis/BasicValueFactory.cpp')
-rw-r--r--lib/Analysis/BasicValueFactory.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/Analysis/BasicValueFactory.cpp b/lib/Analysis/BasicValueFactory.cpp
index 88b360d1d0..22fb2d1b6e 100644
--- a/lib/Analysis/BasicValueFactory.cpp
+++ b/lib/Analysis/BasicValueFactory.cpp
@@ -14,15 +14,32 @@
//===----------------------------------------------------------------------===//
#include "clang/Analysis/PathSensitive/BasicValueFactory.h"
+#include "clang/Analysis/PathSensitive/RValues.h"
using namespace clang;
+typedef std::pair<RVal, unsigned> SizedRVal;
+
+namespace llvm {
+template<> struct FoldingSetTrait<SizedRVal> {
+ static inline void Profile(const SizedRVal& X, llvm::FoldingSetNodeID& ID) {
+ X.first.Profile(ID);
+ ID.AddInteger(X.second);
+ }
+};
+}
+
+typedef llvm::FoldingSet<llvm::FoldingSetNodeWrapper<SizedRVal> >
+ PersistentRValsTy;
+
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
// frees an aux. memory allocated to represent very large constants.
for (APSIntSetTy::iterator I=APSIntSet.begin(), E=APSIntSet.end(); I!=E; ++I)
I->getValue().~APSInt();
+
+ delete (PersistentRValsTy*) PersistentRVals;
}
const llvm::APSInt& BasicValueFactory::getValue(const llvm::APSInt& X) {
@@ -165,3 +182,29 @@ BasicValueFactory::EvaluateAPSInt(BinaryOperator::Opcode Op,
return &getValue( V1 ^ V2 );
}
}
+
+
+const std::pair<RVal, unsigned>&
+BasicValueFactory::getPersistentSizedRVal(const RVal& V, unsigned Bits) {
+
+ // Lazily create the folding set.
+ if (!PersistentRVals) PersistentRVals = new PersistentRValsTy();
+
+ llvm::FoldingSetNodeID ID;
+ void* InsertPos;
+ V.Profile(ID);
+ ID.AddInteger(Bits);
+
+ PersistentRValsTy& Map = *((PersistentRValsTy*) PersistentRVals);
+
+ typedef llvm::FoldingSetNodeWrapper<SizedRVal> FoldNodeTy;
+ FoldNodeTy* P = Map.FindNodeOrInsertPos(ID, InsertPos);
+
+ if (!P) {
+ P = (FoldNodeTy*) BPAlloc.Allocate<FoldNodeTy>();
+ new (P) FoldNodeTy(std::make_pair(V, Bits));
+ Map.InsertNode(P, InsertPos);
+ }
+
+ return *P;
+}