From cb33093b4d342c01b8d01e3a2879da4644a5639e Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Mon, 18 Feb 2008 21:21:23 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47285 91177308-0d34-0410-b5e6-96231b3b80d8 --- Driver/ASTConsumers.cpp | 34 ++++++++++++++++++++++++++++------ Driver/ASTConsumers.h | 4 +++- Driver/clang.cpp | 12 ++++++++++-- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/Driver/ASTConsumers.cpp b/Driver/ASTConsumers.cpp index 73f843f27a..9759e9af73 100644 --- a/Driver/ASTConsumers.cpp +++ b/Driver/ASTConsumers.cpp @@ -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 @@ namespace { 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); + } } //===----------------------------------------------------------------------===// diff --git a/Driver/ASTConsumers.h b/Driver/ASTConsumers.h index 1ea8b1490b..005f797e43 100644 --- a/Driver/ASTConsumers.h +++ b/Driver/ASTConsumers.h @@ -42,7 +42,9 @@ ASTConsumer *CreateDeadStoreChecker(Diagnostic &Diags); 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); diff --git a/Driver/clang.cpp b/Driver/clang.cpp index 4c6a47c90d..08eef52acc 100644 --- a/Driver/clang.cpp +++ b/Driver/clang.cpp @@ -448,6 +448,14 @@ static void InitializeDiagnostics(Diagnostic &Diags) { Diags.setDiagnosticMapping(diag::w_no_declarators, diag::MAP_IGNORE); } +//===----------------------------------------------------------------------===// +// Analysis-specific options. +//===----------------------------------------------------------------------===// + +static llvm::cl::opt +AnalyzeSpecificFunction("analyze-function", + llvm::cl::desc("Run analysis on specific function.")); + //===----------------------------------------------------------------------===// // Target Triple Processing. //===----------------------------------------------------------------------===// @@ -982,10 +990,10 @@ static ASTConsumer* CreateASTConsumer(const std::string& InFile, 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);