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 #include #include @@ -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 > Macros; std::vector 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,7 +162,9 @@ std::shared_ptr FailedModules; public: - PreprocessorOptions() : UsePredefines(true), DetailedRecord(false), + PreprocessorOptions() : PPTimer("preprocessor", "Preprocessing"), + UsePredefines(true), + DetailedRecord(false), DisablePCHValidation(false), AllowPCHWithCompilerErrors(false), DumpDeserializedPCHDecls(false), @@ -164,6 +172,7 @@ 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 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: 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 {