[PATCH] D36492: [time-report] Add preprocessor timer

Brian Gesiak via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 15 09:54:45 PDT 2017


modocache updated this revision to Diff 111195.
modocache retitled this revision from "[RFC][time-report] Add preprocessor timer" to "[time-report] Add preprocessor timer".
modocache edited the summary of this revision.
modocache removed subscribers: vsk, mzolotukhin.
modocache added a comment.

Add `PreprocessorOptions::getTimer`, and move the timer to the top of `Preprocessor::Lex()`.


https://reviews.llvm.org/D36492

Files:
  include/clang/Lex/PreprocessorOptions.h
  lib/Frontend/CompilerInstance.cpp
  lib/Lex/Preprocessor.cpp


Index: lib/Lex/Preprocessor.cpp
===================================================================
--- lib/Lex/Preprocessor.cpp
+++ lib/Lex/Preprocessor.cpp
@@ -743,6 +743,8 @@
 }
 
 void Preprocessor::Lex(Token &Result) {
+  llvm::TimeRegion(PPOpts->getTimer());
+
   // We loop here until a lex function returns a token; this avoids recursion.
   bool ReturnedToken;
   do {
Index: lib/Frontend/CompilerInstance.cpp
===================================================================
--- lib/Frontend/CompilerInstance.cpp
+++ lib/Frontend/CompilerInstance.cpp
@@ -367,7 +367,9 @@
 // Preprocessor
 
 void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
-  const PreprocessorOptions &PPOpts = getPreprocessorOpts();
+  PreprocessorOptions &PPOpts = getPreprocessorOpts();
+  if (getFrontendOpts().ShowTimers)
+    PPOpts.ShowTimers = true;
 
   // Create a PTH manager if we are using some form of a token cache.
   PTHManager *PTHMgr = nullptr;
Index: include/clang/Lex/PreprocessorOptions.h
===================================================================
--- include/clang/Lex/PreprocessorOptions.h
+++ include/clang/Lex/PreprocessorOptions.h
@@ -14,6 +14,7 @@
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSet.h"
+#include "llvm/Support/Timer.h"
 #include <cassert>
 #include <set>
 #include <string>
@@ -37,10 +38,11 @@
   /// \brief libstdc++
   ARCXX_libstdcxx
 };
-  
+
 /// PreprocessorOptions - This class is used for passing the various options
 /// used in preprocessor initialization to InitializePreprocessor().
 class PreprocessorOptions {
+  llvm::Timer PPTimer;
 public:
   std::vector<std::pair<std::string, bool/*isUndef*/> > Macros;
   std::vector<std::string> Includes;
@@ -127,7 +129,11 @@
   /// manipulation of the compiler invocation object, in cases where the 
   /// compiler invocation and its buffers will be reused.
   bool RetainRemappedFileBuffers;
-  
+
+  /// \brief Whether to measure the amount of time spent in code related to
+  /// preprocessing. This flag defaults to false.
+  bool ShowTimers;
+
   /// \brief The Objective-C++ ARC standard library that we should support,
   /// by providing appropriate definitions to retrofit the standard library
   /// with support for lifetime-qualified pointers.
@@ -156,14 +162,17 @@
   std::shared_ptr<FailedModulesSet> FailedModules;
 
 public:
-  PreprocessorOptions() : UsePredefines(true), DetailedRecord(false),
+  PreprocessorOptions() : PPTimer("preprocessor", "Preprocessing"),
+                          UsePredefines(true),
+                          DetailedRecord(false),
                           DisablePCHValidation(false),
                           AllowPCHWithCompilerErrors(false),
                           DumpDeserializedPCHDecls(false),
                           PrecompiledPreambleBytes(0, true),
                           GeneratePreamble(false),
                           RemappedFilesKeepOriginalName(true),
                           RetainRemappedFileBuffers(false),
+                          ShowTimers(false),
                           ObjCXXARCStandardLibrary(ARCXX_nolib) { }
 
   void addMacroDef(StringRef Name) { Macros.emplace_back(Name, false); }
@@ -197,6 +206,10 @@
     PrecompiledPreambleBytes.first = 0;
     PrecompiledPreambleBytes.second = 0;
   }
+
+  llvm::Timer *getTimer() {
+    return ShowTimers ? &PPTimer : nullptr;
+  }
 };
 
 } // end namespace clang


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36492.111195.patch
Type: text/x-patch
Size: 3476 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170815/364503c1/attachment.bin>


More information about the cfe-commits mailing list