[cfe-commits] r47285 - in /cfe/trunk/Driver: ASTConsumers.cpp ASTConsumers.h clang.cpp

Ted Kremenek kremenek at apple.com
Mon Feb 18 13:21:23 PST 2008


Author: kremenek
Date: Mon Feb 18 15:21:23 2008
New Revision: 47285

URL: http://llvm.org/viewvc/llvm-project?rev=47285&view=rev
Log:
Running -grsimple now emits diagnostics about the time spent analyzing each function.  Will
probably make this a separate command line option later.

Added "--analyze-function" option to the driver to (gradually) allow different
analyses to only be run on specific functions. Currently only --grsimple uses
this option.

Modified:
    cfe/trunk/Driver/ASTConsumers.cpp
    cfe/trunk/Driver/ASTConsumers.h
    cfe/trunk/Driver/clang.cpp

Modified: cfe/trunk/Driver/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.cpp?rev=47285&r1=47284&r2=47285&view=diff

==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Mon Feb 18 15:21:23 2008
@@ -23,6 +23,7 @@
 #include "clang/Analysis/Analyses/GRSimpleVals.h"
 #include "clang/Analysis/LocalCheckers.h"
 #include "llvm/Support/Streams.h"
+#include "llvm/Support/Timer.h"
 using namespace clang;
 
 //===----------------------------------------------------------------------===//
@@ -581,22 +582,43 @@
     Diagnostic &Diags;
     ASTContext* Ctx;
     bool Visualize;
+    std::string FName;
   public:
-    GRSimpleValsVisitor(Diagnostic &diags, bool visualize)
-      : Diags(diags), Visualize(visualize) {}
+    GRSimpleValsVisitor(Diagnostic &diags, const std::string& fname, bool visualize)
+      : Diags(diags), Visualize(visualize), FName(fname) {}
     
     virtual void Initialize(ASTContext &Context) { Ctx = &Context; }    
     virtual void VisitCFG(CFG& C, FunctionDecl&);
-    virtual bool printFuncDeclStart() { return Visualize; }
+    virtual bool printFuncDeclStart() { return false; }
   };
 } // end anonymous namespace
 
-ASTConsumer* clang::CreateGRSimpleVals(Diagnostic &Diags, bool Visualize) {
-  return new GRSimpleValsVisitor(Diags, Visualize);
+ASTConsumer* clang::CreateGRSimpleVals(Diagnostic &Diags,
+                                       const std::string& FunctionName,
+                                       bool Visualize) {
+  
+  return new GRSimpleValsVisitor(Diags, FunctionName, Visualize);
 }
 
 void GRSimpleValsVisitor::VisitCFG(CFG& C, FunctionDecl& FD) {
-  RunGRSimpleVals(C, FD, *Ctx, Diags, Visualize);
+  if (FName.size() > 0 && FName != FD.getIdentifier()->getName())
+    return;
+  
+  if (!Visualize) {
+    llvm::cerr << "ANALYZE: " << FD.getIdentifier()->getName() << ' '
+               << Ctx->getSourceManager().getSourceName(FD.getLocation())
+               << ' ';
+
+    llvm::Timer T("GRSimpleVals");
+    T.startTimer();
+    RunGRSimpleVals(C, FD, *Ctx, Diags, Visualize);
+    T.stopTimer();    
+    llvm::cerr << T.getWallTime() << '\n';
+  }
+  else {  
+    llvm::cerr << '\n';    
+    RunGRSimpleVals(C, FD, *Ctx, Diags, Visualize);
+  }    
 }
 
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/Driver/ASTConsumers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.h?rev=47285&r1=47284&r2=47285&view=diff

==============================================================================
--- cfe/trunk/Driver/ASTConsumers.h (original)
+++ cfe/trunk/Driver/ASTConsumers.h Mon Feb 18 15:21:23 2008
@@ -42,7 +42,9 @@
 
 ASTConsumer *CreateUnitValsChecker(Diagnostic &Diags);
   
-ASTConsumer *CreateGRSimpleVals(Diagnostic &Diags, bool Visualize = false);
+ASTConsumer *CreateGRSimpleVals(Diagnostic &Diags,
+                                const std::string& Function,
+                                bool Visualize = false);
 
 ASTConsumer *CreateCodeRewriterTest(const std::string& InFile,
                                     Diagnostic &Diags);

Modified: cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/clang.cpp?rev=47285&r1=47284&r2=47285&view=diff

==============================================================================
--- cfe/trunk/Driver/clang.cpp (original)
+++ cfe/trunk/Driver/clang.cpp Mon Feb 18 15:21:23 2008
@@ -449,6 +449,14 @@
 }
 
 //===----------------------------------------------------------------------===//
+// Analysis-specific options.
+//===----------------------------------------------------------------------===//
+
+static llvm::cl::opt<std::string>
+AnalyzeSpecificFunction("analyze-function",
+                llvm::cl::desc("Run analysis on specific function."));
+
+//===----------------------------------------------------------------------===//
 // Target Triple Processing.
 //===----------------------------------------------------------------------===//
 
@@ -982,10 +990,10 @@
       return CreateUnitValsChecker(Diag);
       
     case AnalysisGRSimpleVals:
-      return CreateGRSimpleVals(Diag);
+      return CreateGRSimpleVals(Diag, AnalyzeSpecificFunction);
       
     case AnalysisGRSimpleValsView:
-      return CreateGRSimpleVals(Diag, true);
+      return CreateGRSimpleVals(Diag, AnalyzeSpecificFunction, true);
       
     case TestSerialization:
       return CreateSerializationTest(Diag, FileMgr, LangOpts);





More information about the cfe-commits mailing list