Hey,

Ok to commit?

This patch moves the frontend timer from clang-cc into CompilerInstance.
CompilerInstance already contains various objects that are used
throughout the entire run.

-- 
Best regards,
Kovarththanan Rajaratnam
Index: include/clang/Frontend/CompilerInstance.h
===================================================================
--- include/clang/Frontend/CompilerInstance.h	(revision 89876)
+++ include/clang/Frontend/CompilerInstance.h	(working copy)
@@ -21,6 +21,7 @@
 class LLVMContext;
 class raw_ostream;
 class raw_fd_ostream;
+class Timer;
 }
 
 namespace clang {
@@ -89,6 +90,9 @@
   /// 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;
 
@@ -367,6 +371,17 @@
   void setCodeCompletionConsumer(CodeCompleteConsumer *Value);
 
   /// }
+  /// @name Frontend timer
+  /// {
+
+  bool hasFrontendTimer() const { return FrontendTimer != 0; }
+
+  llvm::Timer &getFrontendTimer() const {
+    assert(FrontendTimer && "Compiler instance has no fronend timer!");
+    return *FrontendTimer;
+  }
+
+  /// }
   /// @name Output Files
   /// {
 
@@ -462,6 +477,9 @@
                                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: include/clang/Frontend/FrontendAction.h
===================================================================
--- include/clang/Frontend/FrontendAction.h	(revision 89876)
+++ include/clang/Frontend/FrontendAction.h	(working copy)
@@ -14,10 +14,6 @@
 #include "llvm/ADT/OwningPtr.h"
 #include <string>
 
-namespace llvm {
-class Timer;
-}
-
 namespace clang {
 class ASTUnit;
 class ASTConsumer;
@@ -29,7 +25,6 @@
   std::string CurrentFile;
   llvm::OwningPtr<ASTUnit> CurrentASTUnit;
   CompilerInstance *Instance;
-  llvm::Timer *CurrentTimer;
 
 protected:
   /// @name Implementation Action Interface
@@ -112,18 +107,6 @@
   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: tools/clang-cc/clang-cc.cpp
===================================================================
--- tools/clang-cc/clang-cc.cpp	(revision 89876)
+++ tools/clang-cc/clang-cc.cpp	(working copy)
@@ -74,11 +74,6 @@
   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 @@
                  << " hosted on " << llvm::sys::getHostTriple() << "\n";
 
   if (Clang.getFrontendOpts().ShowTimers)
-    ClangFrontendTimer = new llvm::Timer("Clang front-end time");
+    Clang.createFrontendTimer();
 
   // Enforce certain implications.
   if (!Clang.getFrontendOpts().ViewClassInheritance.empty())
@@ -278,7 +273,6 @@
     if (!Act)
       break;
 
-    Act->setCurrentTimer(ClangFrontendTimer);
     if (Act->BeginSourceFile(Clang, InFile, IsAST)) {
       Act->Execute();
       Act->EndSourceFile();
@@ -295,8 +289,6 @@
     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
Index: lib/Frontend/CompilerInstance.cpp
===================================================================
--- lib/Frontend/CompilerInstance.cpp	(revision 89876)
+++ lib/Frontend/CompilerInstance.cpp	(working copy)
@@ -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 @@
                                  llvm::outs()));
 }
 
+void CompilerInstance::createFrontendTimer() {
+  FrontendTimer.reset(new llvm::Timer("Clang front-end timer"));
+}
+
 CodeCompleteConsumer *
 CompilerInstance::createCodeCompletionConsumer(Preprocessor &PP,
                                                const std::string &Filename,
Index: lib/Frontend/FrontendAction.cpp
===================================================================
--- lib/Frontend/FrontendAction.cpp	(revision 89876)
+++ lib/Frontend/FrontendAction.cpp	(working copy)
@@ -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,12 @@
       return;
   }
 
-  llvm::TimeRegion Timer(CurrentTimer);
-  ExecuteAction();
+  if (CI.hasFrontendTimer()) {
+    llvm::TimeRegion Timer(CI.getFrontendTimer());
+    ExecuteAction();
+  }
+  else
+    ExecuteAction();
 }
 
 void FrontendAction::EndSourceFile() {
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to