#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/SmallPtrSet.h"
-#include "llvm/ADT/DenseSet.h"
#include "llvm/Support/Allocator.h"
#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/GraphTraits.h"
class ExplodedGraph {
protected:
friend class CoreEngine;
- friend class ExplodedNode;
// Type definitions.
typedef std::vector<ExplodedNode *> NodeVector;
unsigned NumNodes;
/// A list of recently allocated nodes that can potentially be recycled.
- llvm::DenseSet<ExplodedNode*> ChangedNodes;
+ NodeVector ChangedNodes;
/// A list of nodes that can be reused.
NodeVector FreeNodes;
/// A flag that indicates whether nodes should be recycled.
bool reclaimNodes;
+
+ /// Counter to determine when to reclaim nodes.
+ unsigned reclaimCounter;
public:
llvm::DenseMap<const void*, const void*> *InverseMap) const;
/// Enable tracking of recently allocated nodes for potential reclamation
- /// when calling reclaimChangedNodes().
+ /// when calling reclaimRecentlyAllocatedNodes().
void enableNodeReclamation() { reclaimNodes = true; }
/// Reclaim "uninteresting" nodes created since the last time this method
/// was called.
- void reclaimChangedNodes();
+ void reclaimRecentlyAllocatedNodes();
private:
bool shouldCollect(const ExplodedNode *node);
// Cleanup.
//===----------------------------------------------------------------------===//
+static const unsigned CounterTop = 1000;
+
ExplodedGraph::ExplodedGraph()
- : NumNodes(0), reclaimNodes(false) {}
+ : NumNodes(0), reclaimNodes(false), reclaimCounter(CounterTop) {}
ExplodedGraph::~ExplodedGraph() {}
node->~ExplodedNode();
}
-void ExplodedGraph::reclaimChangedNodes() {
+void ExplodedGraph::reclaimRecentlyAllocatedNodes() {
if (ChangedNodes.empty())
return;
- for (llvm::DenseSet<ExplodedNode*>::iterator it =
- ChangedNodes.begin(), et = ChangedNodes.end();
+ // Only periodically relcaim nodes so that we can build up a set of
+ // nodes that meet the reclamation criteria. Freshly created nodes
+ // by definition have no successor, and thus cannot be reclaimed (see below).
+ assert(reclaimCounter > 0);
+ if (--reclaimCounter != 0)
+ return;
+ reclaimCounter = CounterTop;
+
+ for (NodeVector::iterator it = ChangedNodes.begin(), et = ChangedNodes.end();
it != et; ++it) {
ExplodedNode *node = *it;
if (shouldCollect(node))
assert (!V->isSink());
Preds.addNode(V, G);
V->Succs.addNode(this, G);
- if (G.reclaimNodes) {
- if (Succs.size() == 1 && Preds.size() == 1)
- G.ChangedNodes.insert(this);
- if (V->Succs.size() == 1 && V->Preds.size() == 1)
- G.ChangedNodes.insert(V);
- }
#ifndef NDEBUG
if (NodeAuditor) NodeAuditor->AddEdge(V, this);
#endif
new (V) NodeTy(L, State, IsSink);
+ if (reclaimNodes)
+ ChangedNodes.push_back(V);
+
// Insert the node into the node set and return it.
Nodes.InsertNode(V, InsertPos);
++NumNodes;
}
void ExprEngine::ProcessStmt(const CFGStmt S,
- ExplodedNode *Pred) {
+ ExplodedNode *Pred) {
+ // Reclaim any unnecessary nodes in the ExplodedGraph.
+ G.reclaimRecentlyAllocatedNodes();
+
currentStmt = S.getStmt();
PrettyStackTraceLoc CrashInfo(getContext().getSourceManager(),
currentStmt->getLocStart(),