]> granicus.if.org Git - clang/commitdiff
Add a new BFS GRWorkList and make it the default worklist model for
authorTed Kremenek <kremenek@apple.com>
Fri, 1 May 2009 22:18:46 +0000 (22:18 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 1 May 2009 22:18:46 +0000 (22:18 +0000)
GRCoreEngine. This tends to result in shorter paths for pathological cases.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70585 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Analysis/PathSensitive/GRCoreEngine.h
include/clang/Analysis/PathSensitive/GRWorkList.h
lib/Analysis/GRCoreEngine.cpp

index fe8634edad17a9a6f36e0df58467086145158155..93c2884f8b184e2788ee42219d42603a6526b69a 100644 (file)
@@ -631,7 +631,7 @@ public:
   ///  a DFS exploration of the exploded graph.
   GRCoreEngine(CFG& cfg, Decl& cd, ASTContext& ctx, SubEngineTy& subengine)
     : GRCoreEngineImpl(new GraphTy(cfg, cd, ctx),
-                       GRWorkList::MakeBFSBlockDFSContents()),
+                       GRWorkList::MakeBFS()),
       SubEngine(subengine) {}
   
   /// Construct a GRCoreEngine object to analyze the provided CFG and to
index de7ea5ebd6fbc935c23f29e0c42db7d455dd8775..c76532294c1f8f40de3781631d6ab04a51a87100 100644 (file)
@@ -68,8 +68,9 @@ public:
   void setBlockCounter(GRBlockCounter C) { CurrentCounter = C; }
   GRBlockCounter getBlockCounter() const { return CurrentCounter; }
   
-  static GRWorkList* MakeDFS(); 
-  static GRWorkList* MakeBFSBlockDFSContents();
+  static GRWorkList *MakeDFS();
+  static GRWorkList *MakeBFS();
+  static GRWorkList *MakeBFSBlockDFSContents();
 };
 } // end clang namespace  
 #endif
index e4f27b60cf2bec9be1a221a6565a2702b87e33b5..46a2173c96aff700ab1ef0c2c24c904ec2255965 100644 (file)
@@ -47,13 +47,35 @@ public:
     return U;
   }
 };
+  
+class VISIBILITY_HIDDEN BFS : public GRWorkList {
+  std::queue<GRWorkListUnit> Queue;
+public:
+  virtual bool hasWork() const {
+    return !Queue.empty();
+  }
+  
+  virtual void Enqueue(const GRWorkListUnit& U) {
+    Queue.push(U);
+  }
+  
+  virtual GRWorkListUnit Dequeue() {
+    // Don't use const reference.  The subsequent pop_back() might make it
+    // unsafe.
+    GRWorkListUnit U = Queue.front(); 
+    Queue.pop();
+    return U;
+  }
+};
+  
 } // end anonymous namespace
 
 // Place the dstor for GRWorkList here because it contains virtual member
 // functions, and we the code for the dstor generated in one compilation unit.
 GRWorkList::~GRWorkList() {}
 
-GRWorkList* GRWorkList::MakeDFS() { return new DFS(); }
+GRWorkList *GRWorkList::MakeDFS() { return new DFS(); }
+GRWorkList *GRWorkList::MakeBFS() { return new BFS(); }
 
 namespace {
   class VISIBILITY_HIDDEN BFSBlockDFSContents : public GRWorkList {