diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-01-31 02:23:28 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-01-31 02:23:28 +0000 |
commit | 2753ca84f025462122cc57f3004ca7d8d514bb21 (patch) | |
tree | 6b008ff25b3f77ef080e1ffb550b632972551ef3 /clang/lib/StaticAnalyzer/Core/ProgramState.cpp | |
parent | cff58989d729bfc088a4807b0d037138fc3dc643 (diff) | |
download | bcm5719-llvm-2753ca84f025462122cc57f3004ca7d8d514bb21.tar.gz bcm5719-llvm-2753ca84f025462122cc57f3004ca7d8d514bb21.zip |
Reapply r149311 which I reverted by mistake.
Original log:
Convert ProgramStateRef to a smart pointer for managing the reference counts of ProgramStates. This leads to a slight memory
improvement, and a simplification of the logic for managing ProgramState objects.
# Please enter the commit message for your changes. Lines starting
llvm-svn: 149339
Diffstat (limited to 'clang/lib/StaticAnalyzer/Core/ProgramState.cpp')
-rw-r--r-- | clang/lib/StaticAnalyzer/Core/ProgramState.cpp | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/ProgramState.cpp b/clang/lib/StaticAnalyzer/Core/ProgramState.cpp index b8b9ad94df3..459bf83ce5e 100644 --- a/clang/lib/StaticAnalyzer/Core/ProgramState.cpp +++ b/clang/lib/StaticAnalyzer/Core/ProgramState.cpp @@ -25,6 +25,26 @@ using namespace ento; // FIXME: Move this elsewhere. ConstraintManager::~ConstraintManager() {} +namespace clang { namespace ento { +/// Increments the number of times this state is referenced. + +void ProgramStateRetain(const ProgramState *state) { + ++const_cast<ProgramState*>(state)->refCount; +} + +/// Decrement the number of times this state is referenced. +void ProgramStateRelease(const ProgramState *state) { + assert(state->refCount > 0); + ProgramState *s = const_cast<ProgramState*>(state); + if (--s->refCount == 0) { + ProgramStateManager &Mgr = s->getStateManager(); + Mgr.StateSet.RemoveNode(s); + s->~ProgramState(); + Mgr.freeStates.push_back(s); + } +} +}} + ProgramState::ProgramState(ProgramStateManager *mgr, const Environment& env, StoreRef st, GenericDataMap gdm) : stateMgr(mgr), @@ -328,23 +348,10 @@ ProgramStateRef ProgramStateManager::getInitialState(const LocationContext *Init return getPersistentState(State); } -void ProgramStateManager::recycleUnusedStates() { - for (std::vector<ProgramState*>::iterator i = recentlyAllocatedStates.begin(), - e = recentlyAllocatedStates.end(); i != e; ++i) { - ProgramState *state = *i; - if (state->referencedByExplodedNode()) - continue; - StateSet.RemoveNode(state); - freeStates.push_back(state); - state->~ProgramState(); - } - recentlyAllocatedStates.clear(); -} - ProgramStateRef ProgramStateManager::getPersistentStateWithGDM( ProgramStateRef FromState, ProgramStateRef GDMState) { - ProgramState NewState = *FromState; + ProgramState NewState(*FromState); NewState.GDM = GDMState->GDM; return getPersistentState(NewState); } @@ -368,12 +375,11 @@ ProgramStateRef ProgramStateManager::getPersistentState(ProgramState &State) { } new (newState) ProgramState(State); StateSet.InsertNode(newState, InsertPos); - recentlyAllocatedStates.push_back(newState); return newState; } ProgramStateRef ProgramState::makeWithStore(const StoreRef &store) const { - ProgramState NewSt = *this; + ProgramState NewSt(*this); NewSt.setStore(store); return getStateManager().getPersistentState(NewSt); } |