diff options
author | Ted Kremenek <kremenek@apple.com> | 2011-02-10 02:21:52 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2011-02-10 02:21:52 +0000 |
commit | e40b69de464bc695afcaf7ef9602ad727d77b981 (patch) | |
tree | 82f7a6a4cdcb81a79dfebc08711f45f451e9d4b1 | |
parent | b26bd7426dd102273be190bf6fb13f7533838154 (diff) |
static analyzer: Make GRStates reference counted, with reference counts managed by ExplodedNodes.
This reduces memory usage of the analyzer on sqlite by another 5%.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125260 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h | 6 | ||||
-rw-r--r-- | include/clang/StaticAnalyzer/Core/PathSensitive/GRState.h | 36 | ||||
-rw-r--r-- | lib/StaticAnalyzer/Core/ExplodedGraph.cpp | 2 |
3 files changed, 28 insertions, 16 deletions
diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h b/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h index e1cc6fd630..e5d6876fa6 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h @@ -118,7 +118,11 @@ public: 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. diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/GRState.h b/include/clang/StaticAnalyzer/Core/PathSensitive/GRState.h index 3e34e69e5a..a2cbb20e7b 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/GRState.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/GRState.h @@ -79,11 +79,13 @@ private: 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 @@ public: /// 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 @@ public: 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 { diff --git a/lib/StaticAnalyzer/Core/ExplodedGraph.cpp b/lib/StaticAnalyzer/Core/ExplodedGraph.cpp index 84fcacab63..3ce50d6539 100644 --- a/lib/StaticAnalyzer/Core/ExplodedGraph.cpp +++ b/lib/StaticAnalyzer/Core/ExplodedGraph.cpp @@ -123,6 +123,8 @@ void ExplodedGraph::reclaimRecentlyAllocatedNodes() { freeNodes = new NodeList(); getNodeList(freeNodes)->push_back(node); Nodes.RemoveNode(node); + --NumNodes; + node->~ExplodedNode(); } nl.clear(); |