[llvm-branch-commits] [cfe-branch] r119263 - in /cfe/branches/Apple/whitney: include/clang/Checker/PathSensitive/GRWorkList.h lib/Checker/GRCoreEngine.cpp
Daniel Dunbar
daniel at zuster.org
Mon Nov 15 13:46:54 PST 2010
Author: ddunbar
Date: Mon Nov 15 15:46:54 2010
New Revision: 119263
URL: http://llvm.org/viewvc/llvm-project?rev=119263&view=rev
Log:
Merge r118982:
--
Author: Ted Kremenek <kremenek at apple.com>
Date: Sat Nov 13 05:04:49 2010 +0000
Add GRWorkList::VisitItemsInWorkList() to allow a client to introspect the contents of a worklist.
This API required changing the BFS worklist to use a deque instead of a queue, but that is better
for performance reasons anyway.
Modified:
cfe/branches/Apple/whitney/include/clang/Checker/PathSensitive/GRWorkList.h
cfe/branches/Apple/whitney/lib/Checker/GRCoreEngine.cpp
Modified: cfe/branches/Apple/whitney/include/clang/Checker/PathSensitive/GRWorkList.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/include/clang/Checker/PathSensitive/GRWorkList.h?rev=119263&r1=119262&r2=119263&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/include/clang/Checker/PathSensitive/GRWorkList.h (original)
+++ cfe/branches/Apple/whitney/include/clang/Checker/PathSensitive/GRWorkList.h Mon Nov 15 15:46:54 2010
@@ -71,6 +71,14 @@
void setBlockCounter(GRBlockCounter C) { CurrentCounter = C; }
GRBlockCounter getBlockCounter() const { return CurrentCounter; }
+ class Visitor {
+ public:
+ Visitor() {}
+ virtual ~Visitor();
+ virtual bool Visit(const GRWorkListUnit &U) = 0;
+ };
+ virtual bool VisitItemsInWorkList(Visitor &V) = 0;
+
static GRWorkList *MakeDFS();
static GRWorkList *MakeBFS();
static GRWorkList *MakeBFSBlockDFSContents();
Modified: cfe/branches/Apple/whitney/lib/Checker/GRCoreEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Checker/GRCoreEngine.cpp?rev=119263&r1=119262&r2=119263&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Checker/GRCoreEngine.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Checker/GRCoreEngine.cpp Mon Nov 15 15:46:54 2010
@@ -36,6 +36,8 @@
// Worklist classes for exploration of reachable states.
//===----------------------------------------------------------------------===//
+GRWorkList::Visitor::~Visitor() {}
+
namespace {
class DFS : public GRWorkList {
llvm::SmallVector<GRWorkListUnit,20> Stack;
@@ -54,26 +56,42 @@
Stack.pop_back(); // This technically "invalidates" U, but we are fine.
return U;
}
+
+ virtual bool VisitItemsInWorkList(Visitor &V) {
+ for (llvm::SmallVectorImpl<GRWorkListUnit>::iterator
+ I = Stack.begin(), E = Stack.end(); I != E; ++I) {
+ if (V.Visit(*I))
+ return true;
+ }
+ return false;
+ }
};
class BFS : public GRWorkList {
- std::queue<GRWorkListUnit> Queue;
+ std::deque<GRWorkListUnit> Queue;
public:
virtual bool hasWork() const {
return !Queue.empty();
}
virtual void Enqueue(const GRWorkListUnit& U) {
- Queue.push(U);
+ Queue.push_front(U);
}
virtual GRWorkListUnit Dequeue() {
- // Don't use const reference. The subsequent pop_back() might make it
- // unsafe.
GRWorkListUnit U = Queue.front();
- Queue.pop();
+ Queue.pop_front();
return U;
}
+
+ virtual bool VisitItemsInWorkList(Visitor &V) {
+ for (std::deque<GRWorkListUnit>::iterator
+ I = Queue.begin(), E = Queue.end(); I != E; ++I) {
+ if (V.Visit(*I))
+ return true;
+ }
+ return false;
+ }
};
} // end anonymous namespace
@@ -87,7 +105,7 @@
namespace {
class BFSBlockDFSContents : public GRWorkList {
- std::queue<GRWorkListUnit> Queue;
+ std::deque<GRWorkListUnit> Queue;
llvm::SmallVector<GRWorkListUnit,20> Stack;
public:
virtual bool hasWork() const {
@@ -96,7 +114,7 @@
virtual void Enqueue(const GRWorkListUnit& U) {
if (isa<BlockEntrance>(U.getNode()->getLocation()))
- Queue.push(U);
+ Queue.push_front(U);
else
Stack.push_back(U);
}
@@ -113,9 +131,23 @@
// Don't use const reference. The subsequent pop_back() might make it
// unsafe.
GRWorkListUnit U = Queue.front();
- Queue.pop();
+ Queue.pop_front();
return U;
}
+ virtual bool VisitItemsInWorkList(Visitor &V) {
+ for (llvm::SmallVectorImpl<GRWorkListUnit>::iterator
+ I = Stack.begin(), E = Stack.end(); I != E; ++I) {
+ if (V.Visit(*I))
+ return true;
+ }
+ for (std::deque<GRWorkListUnit>::iterator
+ I = Queue.begin(), E = Queue.end(); I != E; ++I) {
+ if (V.Visit(*I))
+ return true;
+ }
+ return false;
+ }
+
};
} // end anonymous namespace
More information about the llvm-branch-commits
mailing list