Added "SymIntConstraint", a utility class to represent intermediate values for
transfer function evaluation that represent constraints between symbolic values
and constant integers.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46769 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Analysis/RValues.cpp b/Analysis/RValues.cpp
index 2854ee6..8861f57 100644
--- a/Analysis/RValues.cpp
+++ b/Analysis/RValues.cpp
@@ -38,7 +38,7 @@
SymbolManager::~SymbolManager() {}
//===----------------------------------------------------------------------===//
-// ValueManager.
+// Values and ValueManager.
//===----------------------------------------------------------------------===//
ValueManager::~ValueManager() {
@@ -49,7 +49,7 @@
I->getValue().~APSInt();
}
-APSInt& ValueManager::getValue(const APSInt& X) {
+const APSInt& ValueManager::getValue(const APSInt& X) {
llvm::FoldingSetNodeID ID;
void* InsertPos;
typedef llvm::FoldingSetNodeWrapper<APSInt> FoldNodeTy;
@@ -66,19 +66,41 @@
return *P;
}
-APSInt& ValueManager::getValue(uint64_t X, unsigned BitWidth, bool isUnsigned) {
+const APSInt& ValueManager::getValue(uint64_t X, unsigned BitWidth,
+ bool isUnsigned) {
APSInt V(BitWidth, isUnsigned);
V = X;
return getValue(V);
}
-APSInt& ValueManager::getValue(uint64_t X, QualType T, SourceLocation Loc) {
+const APSInt& ValueManager::getValue(uint64_t X, QualType T,
+ SourceLocation Loc) {
+
unsigned bits = Ctx.getTypeSize(T, Loc);
APSInt V(bits, T->isUnsignedIntegerType());
V = X;
return getValue(V);
}
+const SymIntConstraint&
+ValueManager::getConstraint(SymbolID sym, BinaryOperator::Opcode Op,
+ const llvm::APSInt& V) {
+
+ llvm::FoldingSetNodeID ID;
+ SymIntConstraint::Profile(ID, sym, Op, V);
+ void* InsertPos;
+
+ SymIntConstraint* C = SymIntCSet.FindNodeOrInsertPos(ID, InsertPos);
+
+ if (!C) {
+ C = (SymIntConstraint*) BPAlloc.Allocate<SymIntConstraint>();
+ new (C) SymIntConstraint(sym, Op, V);
+ SymIntCSet.InsertNode(C, InsertPos);
+ }
+
+ return *C;
+}
+
//===----------------------------------------------------------------------===//
// Transfer function for Casts.
//===----------------------------------------------------------------------===//