[cfe-commits] r48286 - in /cfe/trunk/Analysis: ExplodedGraph.cpp GRExprEngine.cpp GRSimpleVals.cpp

Ted Kremenek kremenek at apple.com
Wed Mar 12 10:18:20 PDT 2008


Author: kremenek
Date: Wed Mar 12 12:18:20 2008
New Revision: 48286

URL: http://llvm.org/viewvc/llvm-project?rev=48286&view=rev
Log:
Improved ExplodedGraph::Trim to only show nodes reachable from a reverse BFS
from the sources, and to try and generate only a single path from sources
to roots.

Modified:
    cfe/trunk/Analysis/ExplodedGraph.cpp
    cfe/trunk/Analysis/GRExprEngine.cpp
    cfe/trunk/Analysis/GRSimpleVals.cpp

Modified: cfe/trunk/Analysis/ExplodedGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/ExplodedGraph.cpp?rev=48286&r1=48285&r2=48286&view=diff

==============================================================================
--- cfe/trunk/Analysis/ExplodedGraph.cpp (original)
+++ cfe/trunk/Analysis/ExplodedGraph.cpp Wed Mar 12 12:18:20 2008
@@ -17,6 +17,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallVector.h"
 #include <vector>
+#include <list>
 
 using namespace clang;
 
@@ -89,7 +90,7 @@
 ExplodedGraphImpl* ExplodedGraphImpl::Trim(ExplodedNodeImpl** BeginSources,
                                            ExplodedNodeImpl** EndSources) const{
   
-  typedef llvm::DenseSet<ExplodedNodeImpl*> Pass1Ty;
+  typedef llvm::DenseMap<ExplodedNodeImpl*, ExplodedNodeImpl*> Pass1Ty;
   typedef llvm::DenseMap<ExplodedNodeImpl*, ExplodedNodeImpl*> Pass2Ty;
   
   Pass1Ty Pass1;
@@ -101,30 +102,58 @@
     
     // Enqueue the source nodes to the first worklist. 
     
-    llvm::SmallVector<ExplodedNodeImpl*, 10> WL1;
+    std::list<std::pair<ExplodedNodeImpl*, ExplodedNodeImpl*> > WL1;
   
     for (ExplodedNodeImpl** I = BeginSources; I != EndSources; ++I)
-      WL1.push_back(*I);
+      WL1.push_back(std::make_pair(*I, *I));
     
     // Process the worklist.
 
     while (!WL1.empty()) {
       
-      ExplodedNodeImpl* N = WL1.back();
+      ExplodedNodeImpl* N = WL1.back().first;
+      ExplodedNodeImpl* Src = WL1.back().second;
+      
       WL1.pop_back();
       
-      if (Pass1.count(N))
+      if (Pass1.find(N) != Pass1.end())
         continue;
       
-      Pass1.insert(N);
+      bool PredHasSameSource = false;
+      bool VisitPreds = true;
+            
+      for (ExplodedNodeImpl** I=N->Preds.begin(), **E=N->Preds.end();
+            I!=E; ++I) {
+        
+        Pass1Ty::iterator pi = Pass1.find(*I);
+        
+        if (pi == Pass1.end())
+          continue;
+        
+        VisitPreds = false;
+        
+        if (pi->second == Src) {
+          PredHasSameSource = true;
+          break;
+        }
+      }
+      
+      if (VisitPreds || !PredHasSameSource) {
+        
+        Pass1[N] = Src;
       
-      if (N->Preds.empty()) {
-        WL2.push_back(N);
-        continue;      
+        if (N->Preds.empty()) {
+          WL2.push_back(N);
+          continue;      
+        }
       }
+      else
+        Pass1[N] = NULL;
       
-      for (ExplodedNodeImpl** I=N->Preds.begin(), **E=N->Preds.end(); I!=E; ++I)
-        WL1.push_back(*I);
+      if (VisitPreds)
+        for (ExplodedNodeImpl** I=N->Preds.begin(), **E=N->Preds.end();
+             I!=E; ++I)
+          WL1.push_front(std::make_pair(*I, Src));
     }
   }
   
@@ -182,8 +211,12 @@
 
       // Enqueue nodes to the worklist that were marked during pass 1.
       
-      if (Pass1.count(*I))
-        WL2.push_back(*I);
+      Pass1Ty::iterator pi = Pass1.find(*I);
+      
+      if (pi == Pass1.end() || pi->second == NULL)
+        continue;
+            
+      WL2.push_back(*I);
     }
     
     if (N->isSink())

Modified: cfe/trunk/Analysis/GRExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/GRExprEngine.cpp?rev=48286&r1=48285&r2=48286&view=diff

==============================================================================
--- cfe/trunk/Analysis/GRExprEngine.cpp (original)
+++ cfe/trunk/Analysis/GRExprEngine.cpp Wed Mar 12 12:18:20 2008
@@ -1805,23 +1805,49 @@
 #endif
 
 #ifndef NDEBUG
+
+template <typename ITERATOR>
+GRExprEngine::NodeTy* GetGraphNode(ITERATOR I) { return *I; }
+
+template <>
+GRExprEngine::NodeTy*
+GetGraphNode<llvm::DenseMap<GRExprEngine::NodeTy*, Expr*>::iterator>
+  (llvm::DenseMap<GRExprEngine::NodeTy*, Expr*>::iterator I) {
+  return I->first;
+}
+
 template <typename ITERATOR>
 static void AddSources(llvm::SmallVector<GRExprEngine::NodeTy*, 10>& Sources,
-                              ITERATOR I, ITERATOR E) {
+                       ITERATOR I, ITERATOR E) {
   
-  for ( ; I != E; ++I )
-    Sources.push_back(*I);
+  llvm::SmallPtrSet<void*,10> CachedSources;
+  
+  for ( ; I != E; ++I ) {
+    GRExprEngine::NodeTy* N = GetGraphNode(I);
+    void* p = N->getLocation().getRawData();
+    
+    if (CachedSources.count(p))
+      continue;
+    
+    CachedSources.insert(p);
+    
+    Sources.push_back(N);
+  }
 }
 #endif
 
 void GRExprEngine::ViewGraph(bool trim) {
 #ifndef NDEBUG  
   if (trim) {
-    llvm::SmallVector<NodeTy*, 10> Sources;
-    AddSources(Sources, null_derefs_begin(), null_derefs_end());
-    AddSources(Sources, undef_derefs_begin(), undef_derefs_end());
+    llvm::SmallVector<NodeTy*, 10> Src;
+    AddSources(Src, null_derefs_begin(), null_derefs_end());
+    AddSources(Src, undef_derefs_begin(), undef_derefs_end());
+    AddSources(Src, explicit_bad_divides_begin(), explicit_bad_divides_end());
+    AddSources(Src, undef_results_begin(), undef_results_end());
+    AddSources(Src, bad_calls_begin(), bad_calls_end());
+    AddSources(Src, undef_arg_begin(), undef_arg_end());
     
-    ViewGraph(&Sources[0], &Sources[0]+Sources.size());
+    ViewGraph(&Src[0], &Src[0]+Src.size());
   }
   else {
     GraphPrintCheckerState = this;

Modified: cfe/trunk/Analysis/GRSimpleVals.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/GRSimpleVals.cpp?rev=48286&r1=48285&r2=48286&view=diff

==============================================================================
--- cfe/trunk/Analysis/GRSimpleVals.cpp (original)
+++ cfe/trunk/Analysis/GRSimpleVals.cpp Wed Mar 12 12:18:20 2008
@@ -101,7 +101,7 @@
   CheckerState->setTransferFunctions(GRSV);
   
   // Execute the worklist algorithm.
-  Eng.ExecuteWorkList(50000);
+  Eng.ExecuteWorkList(100000);
   
   SourceManager& SrcMgr = Ctx.getSourceManager();  
 





More information about the cfe-commits mailing list