From: Ted Kremenek Date: Thu, 16 Feb 2012 20:19:25 +0000 (+0000) Subject: Minor cleanup to node data structures in ExplodedGraph. No functionality change. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=626719bd2c09e27fe7c182724a812d27f59e3819;p=clang Minor cleanup to node data structures in ExplodedGraph. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150719 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h b/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h index 89fe7ddf75..1c81af9586 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h @@ -32,6 +32,7 @@ #include "llvm/Support/Casting.h" #include "clang/Analysis/Support/BumpVector.h" #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h" +#include namespace clang { @@ -241,18 +242,17 @@ protected: friend class CoreEngine; // Type definitions. - typedef SmallVector RootsTy; - typedef SmallVector EndNodesTy; + typedef std::vector NodeVector; - /// Roots - The roots of the simulation graph. Usually there will be only + /// The roots of the simulation graph. Usually there will be only /// one, but clients are free to establish multiple subgraphs within a single /// SimulGraph. Moreover, these subgraphs can often merge when paths from /// different roots reach the same state at the same program location. - RootsTy Roots; + NodeVector Roots; - /// EndNodes - The nodes in the simulation graph which have been - /// specially marked as the endpoint of an abstract simulation path. - EndNodesTy EndNodes; + /// The nodes in the simulation graph which have been + /// specially marked as the endpoint of an abstract simulation path. + NodeVector EndNodes; /// Nodes - The nodes in the graph. llvm::FoldingSet Nodes; @@ -265,10 +265,10 @@ protected: unsigned NumNodes; /// A list of recently allocated nodes that can potentially be recycled. - void *recentlyAllocatedNodes; + NodeVector ChangedNodes; /// A list of nodes that can be reused. - void *freeNodes; + NodeVector FreeNodes; /// A flag that indicates whether nodes should be recycled. bool reclaimNodes; @@ -315,10 +315,10 @@ public: // Iterators. typedef ExplodedNode NodeTy; typedef llvm::FoldingSet AllNodesTy; - typedef NodeTy** roots_iterator; - typedef NodeTy* const * const_roots_iterator; - typedef NodeTy** eop_iterator; - typedef NodeTy* const * const_eop_iterator; + typedef NodeVector::iterator roots_iterator; + typedef NodeVector::const_iterator const_roots_iterator; + typedef NodeVector::iterator eop_iterator; + typedef NodeVector::const_iterator const_eop_iterator; typedef AllNodesTy::iterator node_iterator; typedef AllNodesTy::const_iterator const_node_iterator; diff --git a/lib/StaticAnalyzer/Core/CoreEngine.cpp b/lib/StaticAnalyzer/Core/CoreEngine.cpp index 84b2c594e4..e7c3d2a3b3 100644 --- a/lib/StaticAnalyzer/Core/CoreEngine.cpp +++ b/lib/StaticAnalyzer/Core/CoreEngine.cpp @@ -239,8 +239,8 @@ void CoreEngine::ExecuteWorkListWithInitialState(const LocationContext *L, ProgramStateRef InitState, ExplodedNodeSet &Dst) { ExecuteWorkList(L, Steps, InitState); - for (SmallVectorImpl::iterator I = G->EndNodes.begin(), - E = G->EndNodes.end(); I != E; ++I) { + for (ExplodedGraph::eop_iterator I = G->eop_begin(), + E = G->eop_end(); I != E; ++I) { Dst.Add(*I); } } diff --git a/lib/StaticAnalyzer/Core/ExplodedGraph.cpp b/lib/StaticAnalyzer/Core/ExplodedGraph.cpp index 8868d95c1b..0dcbe1ff4a 100644 --- a/lib/StaticAnalyzer/Core/ExplodedGraph.cpp +++ b/lib/StaticAnalyzer/Core/ExplodedGraph.cpp @@ -45,22 +45,12 @@ void ExplodedNode::SetAuditor(ExplodedNode::Auditor* A) { // Cleanup. //===----------------------------------------------------------------------===// -typedef std::vector NodeList; -static inline NodeList*& getNodeList(void *&p) { return (NodeList*&) p; } - static const unsigned CounterTop = 1000; ExplodedGraph::ExplodedGraph() - : NumNodes(0), recentlyAllocatedNodes(0), - freeNodes(0), reclaimNodes(false), - reclaimCounter(CounterTop) {} - -ExplodedGraph::~ExplodedGraph() { - if (reclaimNodes) { - delete getNodeList(recentlyAllocatedNodes); - delete getNodeList(freeNodes); - } -} + : NumNodes(0), reclaimNodes(false), reclaimCounter(CounterTop) {} + +ExplodedGraph::~ExplodedGraph() {} //===----------------------------------------------------------------------===// // Node reclamation. @@ -131,16 +121,14 @@ void ExplodedGraph::collectNode(ExplodedNode *node) { ExplodedNode *succ = *(node->succ_begin()); pred->replaceSuccessor(succ); succ->replacePredecessor(pred); - if (!freeNodes) - freeNodes = new NodeList(); - getNodeList(freeNodes)->push_back(node); + FreeNodes.push_back(node); Nodes.RemoveNode(node); --NumNodes; node->~ExplodedNode(); } void ExplodedGraph::reclaimRecentlyAllocatedNodes() { - if (!recentlyAllocatedNodes) + if (ChangedNodes.empty()) return; // Only periodically relcaim nodes so that we can build up a set of @@ -150,16 +138,14 @@ void ExplodedGraph::reclaimRecentlyAllocatedNodes() { if (--reclaimCounter != 0) return; reclaimCounter = CounterTop; - - NodeList &nl = *getNodeList(recentlyAllocatedNodes); - - for (NodeList::iterator i = nl.begin(), e = nl.end() ; i != e; ++i) { - ExplodedNode *node = *i; + + for (NodeVector::iterator it = ChangedNodes.begin(), et = ChangedNodes.end(); + it != et; ++it) { + ExplodedNode *node = *it; if (shouldCollect(node)) collectNode(node); } - - nl.clear(); + ChangedNodes.clear(); } //===----------------------------------------------------------------------===// @@ -259,10 +245,9 @@ ExplodedNode *ExplodedGraph::getNode(const ProgramPoint &L, NodeTy* V = Nodes.FindNodeOrInsertPos(profile, InsertPos); if (!V) { - if (freeNodes && !getNodeList(freeNodes)->empty()) { - NodeList *nl = getNodeList(freeNodes); - V = nl->back(); - nl->pop_back(); + if (!FreeNodes.empty()) { + V = FreeNodes.back(); + FreeNodes.pop_back(); } else { // Allocate a new node. @@ -271,15 +256,11 @@ ExplodedNode *ExplodedGraph::getNode(const ProgramPoint &L, new (V) NodeTy(L, State, IsSink); - if (reclaimNodes) { - if (!recentlyAllocatedNodes) - recentlyAllocatedNodes = new NodeList(); - getNodeList(recentlyAllocatedNodes)->push_back(V); - } + if (reclaimNodes) + ChangedNodes.push_back(V); // Insert the node into the node set and return it. Nodes.InsertNode(V, InsertPos); - ++NumNodes; if (IsNew) *IsNew = true;