[cfe-commits] r90073 - in /cfe/trunk: include/clang/Frontend/CompilerInstance.h include/clang/Frontend/FrontendAction.h lib/Frontend/CompilerInstance.cpp lib/Frontend/FrontendAction.cpp tools/clang-cc/clang-cc.cpp

Kovarththanan Rajaratnam kovarththanan.rajaratnam at gmail.com
Sun Nov 29 01:57:35 PST 2009


Author: krj
Date: Sun Nov 29 03:57:35 2009
New Revision: 90073

URL: http://llvm.org/viewvc/llvm-project?rev=90073&view=rev
Log:
This patch moves the frontend timer from clang-cc into CompilerInstance.
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


Modified:
    cfe/trunk/include/clang/Frontend/CompilerInstance.h
    cfe/trunk/include/clang/Frontend/FrontendAction.h
    cfe/trunk/lib/Frontend/CompilerInstance.cpp
    cfe/trunk/lib/Frontend/FrontendAction.cpp
    cfe/trunk/tools/clang-cc/clang-cc.cpp

Modified: cfe/trunk/include/clang/Frontend/CompilerInstance.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompilerInstance.h?rev=90073&r1=90072&r2=90073&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/CompilerInstance.h (original)
+++ cfe/trunk/include/clang/Frontend/CompilerInstance.h Sun Nov 29 03:57:35 2009
@@ -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 frontend 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 *

Modified: cfe/trunk/include/clang/Frontend/FrontendAction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendAction.h?rev=90073&r1=90072&r2=90073&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/FrontendAction.h (original)
+++ cfe/trunk/include/clang/Frontend/FrontendAction.h Sun Nov 29 03:57:35 2009
@@ -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
   /// @{
 

Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=90073&r1=90072&r2=90073&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Sun Nov 29 03:57:35 2009
@@ -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,

Modified: cfe/trunk/lib/Frontend/FrontendAction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendAction.cpp?rev=90073&r1=90072&r2=90073&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/FrontendAction.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendAction.cpp Sun Nov 29 03:57:35 2009
@@ -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 @@
       return;
   }
 
-  llvm::TimeRegion Timer(CurrentTimer);
-  ExecuteAction();
+  if (CI.hasFrontendTimer()) {
+    llvm::TimeRegion Timer(CI.getFrontendTimer());
+    ExecuteAction();
+  }
+  else ExecuteAction();
 }
 
 void FrontendAction::EndSourceFile() {

Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=90073&r1=90072&r2=90073&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Sun Nov 29 03:57:35 2009
@@ -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();
 
   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 @@
     if (!Act)
       break;
 
-    Act->setCurrentTimer(ClangFrontendTimer);
     if (Act->BeginSourceFile(Clang, InFile, IsAST)) {
       Act->Execute();
       Act->EndSourceFile();
@@ -289,8 +283,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





More information about the cfe-commits mailing list