[cfe-commits] r125260 - in /cfe/trunk: include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h include/clang/StaticAnalyzer/Core/PathSensitive/GRState.h lib/StaticAnalyzer/Core/ExplodedGraph.cpp
Ted Kremenek
kremenek at apple.com
Wed Feb 9 18:21:52 PST 2011
Author: kremenek
Date: Wed Feb 9 20:21:52 2011
New Revision: 125260
URL: http://llvm.org/viewvc/llvm-project?rev=125260&view=rev
Log:
static analyzer: Make GRStates reference counted, with reference counts managed by ExplodedNodes.
This reduces memory usage of the analyzer on sqlite by another 5%.
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/GRState.h
cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp
Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h?rev=125260&r1=125259&r2=125260&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h Wed Feb 9 20:21:52 2011
@@ -118,7 +118,11 @@
explicit ExplodedNode(const ProgramPoint& loc, const GRState* state)
: Location(loc), State(state) {
- const_cast<GRState*>(State)->setReferencedByExplodedNode();
+ const_cast<GRState*>(State)->incrementReferenceCount();
+ }
+
+ ~ExplodedNode() {
+ const_cast<GRState*>(State)->decrementReferenceCount();
}
/// getLocation - Returns the edge associated with the given node.
Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/GRState.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/GRState.h?rev=125260&r1=125259&r2=125260&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/GRState.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/GRState.h Wed Feb 9 20:21:52 2011
@@ -79,11 +79,13 @@
friend class GRStateManager;
friend class ExplodedGraph;
+ friend class ExplodedNode;
- llvm::PointerIntPair<GRStateManager *, 1, bool> stateMgr;
+ GRStateManager *stateMgr;
Environment Env; // Maps a Stmt to its current SVal.
Store St; // Maps a location to its current value.
GenericDataMap GDM; // Custom data stored by a client of this class.
+ unsigned refCount;
/// makeWithStore - Return a GRState with the same values as the current
/// state with the exception of using the specified Store.
@@ -94,33 +96,27 @@
/// This ctor is used when creating the first GRState object.
GRState(GRStateManager *mgr, const Environment& env,
Store st, GenericDataMap gdm)
- : stateMgr(mgr, false),
+ : stateMgr(mgr),
Env(env),
St(st),
- GDM(gdm) {}
+ GDM(gdm),
+ refCount(0) {}
/// Copy ctor - We must explicitly define this or else the "Next" ptr
/// in FoldingSetNode will also get copied.
GRState(const GRState& RHS)
: llvm::FoldingSetNode(),
- stateMgr(RHS.stateMgr.getPointer(), false),
+ stateMgr(RHS.stateMgr),
Env(RHS.Env),
St(RHS.St),
- GDM(RHS.GDM) {}
+ GDM(RHS.GDM),
+ refCount(0) {}
/// Return the GRStateManager associated with this state.
- GRStateManager &getStateManager() const {
- return *stateMgr.getPointer();
- }
+ GRStateManager &getStateManager() const { return *stateMgr; }
/// Return true if this state is referenced by a persistent ExplodedNode.
- bool referencedByExplodedNode() const {
- return stateMgr.getInt();
- }
-
- void setReferencedByExplodedNode() {
- stateMgr.setInt(true);
- }
+ bool referencedByExplodedNode() const { return refCount > 0; }
/// getEnvironment - Return the environment associated with this state.
/// The environment is the mapping from expressions to values.
@@ -373,6 +369,16 @@
void printStdErr(CFG &C) const;
void printDOT(llvm::raw_ostream& Out, CFG &C) const;
+
+private:
+ /// Increments the number of times this state is referenced by ExplodeNodes.
+ void incrementReferenceCount() { ++refCount; }
+
+ /// Decrement the number of times this state is referenced by ExplodeNodes.
+ void decrementReferenceCount() {
+ assert(refCount > 0);
+ --refCount;
+ }
};
class GRStateSet {
Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp?rev=125260&r1=125259&r2=125260&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp Wed Feb 9 20:21:52 2011
@@ -123,6 +123,8 @@
freeNodes = new NodeList();
getNodeList(freeNodes)->push_back(node);
Nodes.RemoveNode(node);
+ --NumNodes;
+ node->~ExplodedNode();
}
nl.clear();
More information about the cfe-commits
mailing list