aboutsummaryrefslogtreecommitdiff
path: root/lib/StaticAnalyzer/GRState.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2011-01-25 19:13:54 +0000
committerTed Kremenek <kremenek@apple.com>2011-01-25 19:13:54 +0000
commite3115e257163321ecde429aeae75f1702f099d4c (patch)
tree34db9e0dde393ce1fcd9c0087619f2e5e6444105 /lib/StaticAnalyzer/GRState.cpp
parenta8c17a5babab35f2db26bf218e7571d1af4afedf (diff)
Recycle memory for GRStates that are never referenced
by ExplodedNodes. This leads to about a 4-8% reduction in memory footprint when analyzing functions in sqlite3. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124214 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/StaticAnalyzer/GRState.cpp')
-rw-r--r--lib/StaticAnalyzer/GRState.cpp28
1 files changed, 24 insertions, 4 deletions
diff --git a/lib/StaticAnalyzer/GRState.cpp b/lib/StaticAnalyzer/GRState.cpp
index 60832e8f79..18995b2ce7 100644
--- a/lib/StaticAnalyzer/GRState.cpp
+++ b/lib/StaticAnalyzer/GRState.cpp
@@ -285,6 +285,18 @@ const GRState* GRStateManager::getInitialState(const LocationContext *InitLoc) {
return getPersistentState(State);
}
+void GRStateManager::recycleUnusedStates() {
+ for (std::vector<GRState*>::iterator i = recentlyAllocatedStates.begin(),
+ e = recentlyAllocatedStates.end(); i != e; ++i) {
+ GRState *state = *i;
+ if (state->referencedByExplodedNode())
+ continue;
+ StateSet.RemoveNode(state);
+ freeStates.push_back(state);
+ }
+ recentlyAllocatedStates.clear();
+}
+
const GRState* GRStateManager::getPersistentState(GRState& State) {
llvm::FoldingSetNodeID ID;
@@ -294,10 +306,18 @@ const GRState* GRStateManager::getPersistentState(GRState& State) {
if (GRState* I = StateSet.FindNodeOrInsertPos(ID, InsertPos))
return I;
- GRState* I = (GRState*) Alloc.Allocate<GRState>();
- new (I) GRState(State);
- StateSet.InsertNode(I, InsertPos);
- return I;
+ GRState *newState = 0;
+ if (!freeStates.empty()) {
+ newState = freeStates.back();
+ freeStates.pop_back();
+ }
+ else {
+ newState = (GRState*) Alloc.Allocate<GRState>();
+ }
+ new (newState) GRState(State);
+ StateSet.InsertNode(newState, InsertPos);
+ recentlyAllocatedStates.push_back(newState);
+ return newState;
}
const GRState* GRState::makeWithStore(Store store) const {