]> granicus.if.org Git - clang/commitdiff
This patch moves the frontend timer from clang-cc into CompilerInstance.
authorKovarththanan Rajaratnam <kovarththanan.rajaratnam@gmail.com>
Sun, 29 Nov 2009 09:57:35 +0000 (09:57 +0000)
committerKovarththanan Rajaratnam <kovarththanan.rajaratnam@gmail.com>
Sun, 29 Nov 2009 09:57:35 +0000 (09:57 +0000)
CompilerInstance already contains various objects that are used
throughout the entire run.

Also addresses Daniels review comments in:

http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20091123/024508.html

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

include/clang/Frontend/CompilerInstance.h
include/clang/Frontend/FrontendAction.h
lib/Frontend/CompilerInstance.cpp
lib/Frontend/FrontendAction.cpp
tools/clang-cc/clang-cc.cpp

index ed280508778a347dc3363f27b58b8a6bb14cdd04..d7e7d991f379bbe280df0aa4518c77ec262a5041 100644 (file)
@@ -21,6 +21,7 @@ namespace llvm {
 class LLVMContext;
 class raw_ostream;
 class raw_fd_ostream;
+class Timer;
 }
 
 namespace clang {
@@ -89,6 +90,9 @@ class CompilerInstance {
   /// The code completion consumer.
   llvm::OwningPtr<CodeCompleteConsumer> CompletionConsumer;
 
+  /// The frontend timer
+  llvm::OwningPtr<llvm::Timer> FrontendTimer;
+
   /// The list of active output files.
   std::list< std::pair<std::string, llvm::raw_ostream*> > OutputFiles;
 
@@ -366,6 +370,17 @@ public:
   /// the compiler instance takes ownership of \arg Value.
   void setCodeCompletionConsumer(CodeCompleteConsumer *Value);
 
+  /// }
+  /// @name Frontend timer
+  /// {
+
+  bool hasFrontendTimer() const { return FrontendTimer != 0; }
+
+  llvm::Timer &getFrontendTimer() const {
+    assert(FrontendTimer && "Compiler instance has no frontend timer!");
+    return *FrontendTimer;
+  }
+
   /// }
   /// @name Output Files
   /// {
@@ -462,6 +477,9 @@ public:
                                bool UseDebugPrinter, bool ShowMacros,
                                llvm::raw_ostream &OS);
 
+  /// Create the frontend timer and replace any existing one with it.
+  void createFrontendTimer();
+
   /// Create the default output file (from the invocation's options) and add it
   /// to the list of tracked output files.
   llvm::raw_fd_ostream *
index 469ea535f6aa7e052e794dec372aa98b837c2510..3042767af8747aee7caded917de55931fa95bea7 100644 (file)
 #include "llvm/ADT/OwningPtr.h"
 #include <string>
 
-namespace llvm {
-class Timer;
-}
-
 namespace clang {
 class ASTUnit;
 class ASTConsumer;
@@ -29,7 +25,6 @@ class FrontendAction {
   std::string CurrentFile;
   llvm::OwningPtr<ASTUnit> CurrentASTUnit;
   CompilerInstance *Instance;
-  llvm::Timer *CurrentTimer;
 
 protected:
   /// @name Implementation Action Interface
@@ -111,18 +106,6 @@ public:
 
   void setCurrentFile(llvm::StringRef Value, ASTUnit *AST = 0);
 
-  /// @}
-  /// @name Timing Utilities
-  /// @{
-
-  llvm::Timer *getCurrentTimer() const {
-    return CurrentTimer;
-  }
-
-  void setCurrentTimer(llvm::Timer *Value) {
-    CurrentTimer = Value;
-  }
-
   /// @}
   /// @name Supported Modes
   /// @{
index 872b7713f32f8799f9e303bac81b3231c8d71f22..1cb5993faef09d3d7f784f8bfe42256284360fa0 100644 (file)
@@ -27,6 +27,7 @@
 #include "llvm/LLVMContext.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/Timer.h"
 #include "llvm/System/Path.h"
 using namespace clang;
 
@@ -257,6 +258,10 @@ void CompilerInstance::createCodeCompletionConsumer() {
                                  llvm::outs()));
 }
 
+void CompilerInstance::createFrontendTimer() {
+  FrontendTimer.reset(new llvm::Timer("Clang front-end timer"));
+}
+
 CodeCompleteConsumer *
 CompilerInstance::createCodeCompletionConsumer(Preprocessor &PP,
                                                const std::string &Filename,
index ff63a0dab5f90799da57c8eb3c61e35c94c03f92..91c946c9cf250fecca8ed4da18498fc877799588 100644 (file)
@@ -21,7 +21,7 @@
 #include "llvm/Support/raw_ostream.h"
 using namespace clang;
 
-FrontendAction::FrontendAction() : Instance(0), CurrentTimer(0) {}
+FrontendAction::FrontendAction() : Instance(0) {}
 
 FrontendAction::~FrontendAction() {}
 
@@ -144,8 +144,11 @@ void FrontendAction::Execute() {
       return;
   }
 
-  llvm::TimeRegion Timer(CurrentTimer);
-  ExecuteAction();
+  if (CI.hasFrontendTimer()) {
+    llvm::TimeRegion Timer(CI.getFrontendTimer());
+    ExecuteAction();
+  }
+  else ExecuteAction();
 }
 
 void FrontendAction::EndSourceFile() {
index 3dfe51190db023757d9a4e67ae5e99bad2633661..a5996c6fc509b538761c63df3814370d9b2f55d5 100644 (file)
@@ -74,11 +74,6 @@ static void LLVMErrorHandler(void *UserData, const std::string &Message) {
   exit(1);
 }
 
-/// ClangFrontendTimer - The front-end activities should charge time to it with
-/// TimeRegion.  The -ftime-report option controls whether this will do
-/// anything.
-llvm::Timer *ClangFrontendTimer = 0;
-
 static FrontendAction *CreateFrontendAction(CompilerInstance &CI) {
   using namespace clang::frontend;
 
@@ -244,7 +239,7 @@ int main(int argc, char **argv) {
                  << " hosted on " << llvm::sys::getHostTriple() << "\n";
 
   if (Clang.getFrontendOpts().ShowTimers)
-    ClangFrontendTimer = new llvm::Timer("Clang front-end time");
+    Clang.createFrontendTimer();
 
   for (unsigned i = 0, e = Clang.getFrontendOpts().Inputs.size(); i != e; ++i) {
     const std::string &InFile = Clang.getFrontendOpts().Inputs[i].second;
@@ -272,7 +267,6 @@ int main(int argc, char **argv) {
     if (!Act)
       break;
 
-    Act->setCurrentTimer(ClangFrontendTimer);
     if (Act->BeginSourceFile(Clang, InFile, IsAST)) {
       Act->Execute();
       Act->EndSourceFile();
@@ -289,8 +283,6 @@ int main(int argc, char **argv) {
     fprintf(stderr, "\n");
   }
 
-  delete ClangFrontendTimer;
-
   // Return the appropriate status when verifying diagnostics.
   //
   // FIXME: If we could make getNumErrors() do the right thing, we wouldn't need