[cfe-commits] r46769 - in /cfe/trunk/Analysis: RValues.cpp RValues.h
Ted Kremenek
kremenek at apple.com
Tue Feb 5 13:32:43 PST 2008
Author: kremenek
Date: Tue Feb 5 15:32:43 2008
New Revision: 46769
URL: http://llvm.org/viewvc/llvm-project?rev=46769&view=rev
Log:
Added "SymIntConstraint", a utility class to represent intermediate values for
transfer function evaluation that represent constraints between symbolic values
and constant integers.
Modified:
cfe/trunk/Analysis/RValues.cpp
cfe/trunk/Analysis/RValues.h
Modified: cfe/trunk/Analysis/RValues.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/RValues.cpp?rev=46769&r1=46768&r2=46769&view=diff
==============================================================================
--- cfe/trunk/Analysis/RValues.cpp (original)
+++ cfe/trunk/Analysis/RValues.cpp Tue Feb 5 15:32:43 2008
@@ -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.
//===----------------------------------------------------------------------===//
Modified: cfe/trunk/Analysis/RValues.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/RValues.h?rev=46769&r1=46768&r2=46769&view=diff
==============================================================================
--- cfe/trunk/Analysis/RValues.h (original)
+++ cfe/trunk/Analysis/RValues.h Tue Feb 5 15:32:43 2008
@@ -37,7 +37,7 @@
#include <functional>
//==------------------------------------------------------------------------==//
-// RValue "management" data structures.
+// Values and ValueManager.
//==------------------------------------------------------------------------==//
namespace clang {
@@ -51,7 +51,10 @@
bool isInitialized() const { return Data != (unsigned) ~0; }
operator unsigned() const { assert (isInitialized()); return Data; }
- void Profile(llvm::FoldingSetNodeID& ID) const { ID.AddInteger(Data); }
+ void Profile(llvm::FoldingSetNodeID& ID) const {
+ assert (isInitialized());
+ ID.AddInteger(Data);
+ }
static inline void Profile(llvm::FoldingSetNodeID& ID, SymbolID X) {
X.Profile(ID);
@@ -70,6 +73,36 @@
inline void* getPtr() const { return reinterpret_cast<void*>(Data & ~Mask); }
inline bool operator==(const SymbolData& R) const { return Data == R.Data; }
};
+
+
+class SymIntConstraint : public llvm::FoldingSetNode {
+ SymbolID Symbol;
+ BinaryOperator::Opcode Op;
+ const llvm::APSInt& Val;
+public:
+ SymIntConstraint(SymbolID sym, BinaryOperator::Opcode op,
+ const llvm::APSInt& V)
+ : Symbol(sym),
+ Op(op), Val(V) {}
+
+ BinaryOperator::Opcode getOpcode() const { return Op; }
+ SymbolID getSymbol() const { return Symbol; }
+ const llvm::APSInt& getInt() const { return Val; }
+
+ static inline void Profile(llvm::FoldingSetNodeID& ID,
+ const SymbolID& Symbol,
+ BinaryOperator::Opcode Op,
+ const llvm::APSInt& Val) {
+ Symbol.Profile(ID);
+ ID.AddInteger(Op);
+ ID.AddPointer(&Val);
+ }
+
+ void Profile(llvm::FoldingSetNodeID& ID) {
+ Profile(ID, Symbol, Op, Val);
+ }
+};
+
class SymbolManager {
std::vector<SymbolData> SymbolToData;
@@ -88,15 +121,22 @@
SymbolID getSymbol(ParmVarDecl* D);
};
+
class ValueManager {
typedef llvm::FoldingSet<llvm::FoldingSetNodeWrapper<llvm::APSInt> >
APSIntSetTy;
+ typedef llvm::FoldingSet<SymIntConstraint>
+ SymIntCSetTy;
+
+
ASTContext& Ctx;
- APSIntSetTy APSIntSet;
llvm::BumpPtrAllocator& BPAlloc;
+ APSIntSetTy APSIntSet;
+ SymIntCSetTy SymIntCSet;
+
public:
ValueManager(ASTContext& ctx, llvm::BumpPtrAllocator& Alloc)
: Ctx(ctx), BPAlloc(Alloc) {}
@@ -104,10 +144,13 @@
~ValueManager();
ASTContext& getContext() const { return Ctx; }
- llvm::APSInt& getValue(const llvm::APSInt& X);
- llvm::APSInt& getValue(uint64_t X, unsigned BitWidth, bool isUnsigned);
- llvm::APSInt& getValue(uint64_t X, QualType T,
- SourceLocation Loc = SourceLocation());
+ const llvm::APSInt& getValue(const llvm::APSInt& X);
+ const llvm::APSInt& getValue(uint64_t X, unsigned BitWidth, bool isUnsigned);
+ const llvm::APSInt& getValue(uint64_t X, QualType T,
+ SourceLocation Loc = SourceLocation());
+
+ const SymIntConstraint& getConstraint(SymbolID sym, BinaryOperator::Opcode Op,
+ const llvm::APSInt& V);
};
//==------------------------------------------------------------------------==//
More information about the cfe-commits
mailing list