Index: include/clang/Frontend/FrontendAction.h =================================================================== --- include/clang/Frontend/FrontendAction.h +++ include/clang/Frontend/FrontendAction.h @@ -45,6 +45,9 @@ StringRef InFile); protected: + static constexpr const char *GroupName = "factions"; + static constexpr const char *GroupDescription = + "===== Frontend Actions ====="; /// @name Implementation Action Interface /// @{ Index: include/clang/Lex/HeaderSearch.h =================================================================== --- include/clang/Lex/HeaderSearch.h +++ include/clang/Lex/HeaderSearch.h @@ -21,9 +21,10 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/StringMap.h" -#include "llvm/ADT/StringSet.h" #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/StringSet.h" #include "llvm/Support/Allocator.h" +#include "llvm/Support/Timer.h" #include #include #include @@ -31,6 +32,9 @@ #include #include +static const char *const IncGroupName = "includefiles"; +static const char *const IncGroupDescription = "===== Include Files ====="; + namespace clang { class DiagnosticsEngine; Index: include/clang/Parse/Parser.h =================================================================== --- include/clang/Parse/Parser.h +++ include/clang/Parse/Parser.h @@ -2850,4 +2850,6 @@ } // end namespace clang +static const char *const GroupName = "clangparser"; +static const char *const GroupDescription = "===== Clang Parser ====="; #endif Index: include/clang/Sema/Sema.h =================================================================== --- include/clang/Sema/Sema.h +++ include/clang/Sema/Sema.h @@ -304,6 +304,9 @@ bool shouldLinkPossiblyHiddenDecl(LookupResult &Old, const NamedDecl *New); public: + static constexpr const char *GroupName = "sema"; + static constexpr const char *GroupDescription = "===== Sema ====="; + typedef OpaquePtr DeclGroupPtrTy; typedef OpaquePtr TemplateTy; typedef OpaquePtr TypeTy; Index: lib/CodeGen/CodeGenAction.cpp =================================================================== --- lib/CodeGen/CodeGenAction.cpp +++ lib/CodeGen/CodeGenAction.cpp @@ -23,6 +23,7 @@ #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Lex/Preprocessor.h" +#include "clang/Rewrite/Frontend/FrontendActions.h" #include "llvm/Bitcode/BitcodeReader.h" #include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h" #include "llvm/IR/DebugInfo.h" @@ -51,7 +52,7 @@ public: ClangDiagnosticHandler(const CodeGenOptions &CGOpts, BackendConsumer *BCon) : CodeGenOpts(CGOpts), BackendCon(BCon) {} - + bool handleDiagnostics(const DiagnosticInfo &DI) override; bool isAnalysisRemarkEnabled(StringRef PassName) const override { @@ -90,9 +91,8 @@ const LangOptions &LangOpts; std::unique_ptr AsmOutStream; ASTContext *Context; - - Timer LLVMIRGeneration; - unsigned LLVMIRGenerationRefCount; + static constexpr const char *GroupName = "frontend"; + static constexpr const char *GroupDescription = "===== Frontend ====="; /// True if we've finished generating IR. This prevents us from generating /// additional LLVM IR after emitting output in HandleTranslationUnit. This @@ -121,8 +121,6 @@ : Diags(Diags), Action(Action), HeaderSearchOpts(HeaderSearchOpts), CodeGenOpts(CodeGenOpts), TargetOpts(TargetOpts), LangOpts(LangOpts), AsmOutStream(std::move(OS)), Context(nullptr), - LLVMIRGeneration("irgen", "LLVM IR Generation Time"), - LLVMIRGenerationRefCount(0), Gen(CreateLLVMCodeGen(Diags, InFile, HeaderSearchOpts, PPOpts, CodeGenOpts, C, CoverageInfo)), LinkModules(std::move(LinkModules)) { @@ -141,38 +139,22 @@ void Initialize(ASTContext &Ctx) override { assert(!Context && "initialized multiple times"); - Context = &Ctx; - - if (llvm::TimePassesIsEnabled) - LLVMIRGeneration.startTimer(); - + NamedRegionTimer T("initbackendconsumer", "Init Backend Consumer", + GroupName, GroupDescription, + llvm::TimePassesIsEnabled); Gen->Initialize(Ctx); - - if (llvm::TimePassesIsEnabled) - LLVMIRGeneration.stopTimer(); } bool HandleTopLevelDecl(DeclGroupRef D) override { PrettyStackTraceDecl CrashInfo(*D.begin(), SourceLocation(), Context->getSourceManager(), "LLVM IR generation of declaration"); - - // Recurse. - if (llvm::TimePassesIsEnabled) { - LLVMIRGenerationRefCount += 1; - if (LLVMIRGenerationRefCount == 1) - LLVMIRGeneration.startTimer(); - } + NamedRegionTimer T("HandleTopLevelDecl", "Handle Top Level Decl", + GroupName, GroupDescription, + llvm::TimePassesIsEnabled); Gen->HandleTopLevelDecl(D); - - if (llvm::TimePassesIsEnabled) { - LLVMIRGenerationRefCount -= 1; - if (LLVMIRGenerationRefCount == 0) - LLVMIRGeneration.stopTimer(); - } - return true; } @@ -180,13 +162,11 @@ PrettyStackTraceDecl CrashInfo(D, SourceLocation(), Context->getSourceManager(), "LLVM IR generation of inline function"); - if (llvm::TimePassesIsEnabled) - LLVMIRGeneration.startTimer(); + NamedRegionTimer T("HandleInlineFunctionDefinition", + "Handle Inline Function Definition", GroupName, + GroupDescription, llvm::TimePassesIsEnabled); Gen->HandleInlineFunctionDefinition(D); - - if (llvm::TimePassesIsEnabled) - LLVMIRGeneration.stopTimer(); } void HandleInterestingDecl(DeclGroupRef D) override { @@ -197,6 +177,8 @@ // Links each entry in LinkModules into our module. Returns true on error. bool LinkInModules() { + NamedRegionTimer T("LinkInModules", "Link In Modules", GroupName, + GroupDescription, llvm::TimePassesIsEnabled); for (auto &LM : LinkModules) { if (LM.PropagateAttrs) for (Function &F : *LM.Module) @@ -227,21 +209,12 @@ void HandleTranslationUnit(ASTContext &C) override { { PrettyStackTraceString CrashInfo("Per-file LLVM IR generation"); - if (llvm::TimePassesIsEnabled) { - LLVMIRGenerationRefCount += 1; - if (LLVMIRGenerationRefCount == 1) - LLVMIRGeneration.startTimer(); - } + NamedRegionTimer T("HandleTranslationUnit", "Handle Translation Unit", + GroupName, GroupDescription, + llvm::TimePassesIsEnabled); Gen->HandleTranslationUnit(C); - - if (llvm::TimePassesIsEnabled) { - LLVMIRGenerationRefCount -= 1; - if (LLVMIRGenerationRefCount == 0) - LLVMIRGeneration.stopTimer(); - } - - IRGenFinished = true; + IRGenFinished = true; } // Silently ignore if we weren't initialized for some reason. @@ -309,23 +282,37 @@ } void HandleTagDeclRequiredDefinition(const TagDecl *D) override { + NamedRegionTimer T("HandleTagDeclRequiredDefinition", + "Handle Tag Decl Required Definition", GroupName, + GroupDescription, llvm::TimePassesIsEnabled); Gen->HandleTagDeclRequiredDefinition(D); } void CompleteTentativeDefinition(VarDecl *D) override { + NamedRegionTimer T("CompleteTentativeDefinition", + "Complete Tentative Definition", GroupName, + GroupDescription, llvm::TimePassesIsEnabled); Gen->CompleteTentativeDefinition(D); } void AssignInheritanceModel(CXXRecordDecl *RD) override { + NamedRegionTimer T("AssignInheritanceModel", "Assign Inheritance Model", + GroupName, GroupDescription, + llvm::TimePassesIsEnabled); Gen->AssignInheritanceModel(RD); } void HandleVTable(CXXRecordDecl *RD) override { + NamedRegionTimer T("HandleVTable", "Handle VTable", GroupName, + GroupDescription, llvm::TimePassesIsEnabled); Gen->HandleVTable(RD); } static void InlineAsmDiagHandler(const llvm::SMDiagnostic &SM,void *Context, unsigned LocCookie) { + NamedRegionTimer T("InlineAsmDiagHandler", "Inline Asm Diag Handler", + GroupName, GroupDescription, + llvm::TimePassesIsEnabled); SourceLocation Loc = SourceLocation::getFromRawEncoding(LocCookie); ((BackendConsumer*)Context)->InlineAsmDiagHandler2(SM, Loc); } @@ -932,6 +919,8 @@ } std::unique_ptr CodeGenAction::loadModule(MemoryBufferRef MBRef) { + NamedRegionTimer T("loadModule", "Load Module", GroupName, GroupDescription, + llvm::TimePassesIsEnabled); CompilerInstance &CI = getCompilerInstance(); SourceManager &SM = CI.getSourceManager(); @@ -999,6 +988,8 @@ void CodeGenAction::ExecuteAction() { // If this is an IR file, we have to treat it specially. if (getCurrentFileKind().getLanguage() == InputKind::LLVM_IR) { + NamedRegionTimer T("ExecuteAction", "LLVM_IR ExecuteAction", GroupName, + GroupDescription, llvm::TimePassesIsEnabled); BackendAction BA = static_cast(Act); CompilerInstance &CI = getCompilerInstance(); std::unique_ptr OS = Index: lib/CodeGen/CodeGenModule.cpp =================================================================== --- lib/CodeGen/CodeGenModule.cpp +++ lib/CodeGen/CodeGenModule.cpp @@ -56,10 +56,14 @@ #include "llvm/Support/ConvertUTF.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MD5.h" +#include "llvm/Support/Timer.h" using namespace clang; using namespace CodeGen; +static const char *const GroupName = "codegenmodule"; +static const char *const GroupDescription = "===== Code Gen Module ====="; + static llvm::cl::opt LimitedCoverage( "limited-coverage-experimental", llvm::cl::ZeroOrMore, llvm::cl::Hidden, llvm::cl::desc("Emit limited coverage mapping information (experimental)"), Index: lib/Frontend/ASTMerge.cpp =================================================================== --- lib/Frontend/ASTMerge.cpp +++ lib/Frontend/ASTMerge.cpp @@ -6,13 +6,14 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#include "clang/Frontend/ASTUnit.h" #include "clang/AST/ASTContext.h" #include "clang/AST/ASTDiagnostic.h" #include "clang/AST/ASTImporter.h" #include "clang/Basic/Diagnostic.h" +#include "clang/Frontend/ASTUnit.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendActions.h" +#include "llvm/Support/Timer.h" using namespace clang; @@ -31,6 +32,8 @@ } void ASTMergeAction::ExecuteAction() { + llvm::NamedRegionTimer T("astmerge", "AST Merge actions", GroupName, + GroupDescription, llvm::TimePassesIsEnabled); CompilerInstance &CI = getCompilerInstance(); CI.getDiagnostics().getClient()->BeginSourceFile( CI.getASTContext().getLangOpts()); Index: lib/Frontend/CompilerInstance.cpp =================================================================== --- lib/Frontend/CompilerInstance.cpp +++ lib/Frontend/CompilerInstance.cpp @@ -54,6 +54,8 @@ #include using namespace clang; +static const char *const GroupName = "frontend"; +static const char *const GroupDescription = "===== Frontend ====="; CompilerInstance::CompilerInstance( std::shared_ptr PCHContainerOps, @@ -937,6 +939,10 @@ assert(!getFrontendOpts().ShowHelp && "Client must handle '-help'!"); assert(!getFrontendOpts().ShowVersion && "Client must handle '-version'!"); + llvm::NamedRegionTimer T("compilerinstance", "Compiler Instance actions", + GroupName, GroupDescription, + llvm::TimePassesIsEnabled); + // FIXME: Take this as an argument, once all the APIs we used have moved to // taking it as an input instead of hard-coding llvm::errs. raw_ostream &OS = llvm::errs(); Index: lib/Frontend/FrontendAction.cpp =================================================================== --- lib/Frontend/FrontendAction.cpp +++ lib/Frontend/FrontendAction.cpp @@ -23,6 +23,7 @@ #include "clang/Lex/Preprocessor.h" #include "clang/Lex/PreprocessorOptions.h" #include "clang/Parse/ParseAST.h" +#include "clang/Rewrite/Frontend/FrontendActions.h" #include "clang/Serialization/ASTDeserializationListener.h" #include "clang/Serialization/ASTReader.h" #include "clang/Serialization/GlobalModuleIndex.h" @@ -894,14 +895,15 @@ return false; } +static int action_number = 0; + bool FrontendAction::Execute() { CompilerInstance &CI = getCompilerInstance(); if (CI.hasFrontendTimer()) { llvm::TimeRegion Timer(CI.getFrontendTimer()); ExecuteAction(); - } - else ExecuteAction(); + } else ExecuteAction(); // If we are supposed to rebuild the global module index, do so now unless // there were any module-build failures. Index: lib/Frontend/FrontendActions.cpp =================================================================== --- lib/Frontend/FrontendActions.cpp +++ lib/Frontend/FrontendActions.cpp @@ -261,6 +261,8 @@ } void VerifyPCHAction::ExecuteAction() { + llvm::NamedRegionTimer T("verifypch", "Verify PCH actions", GroupName, + GroupDescription, llvm::TimePassesIsEnabled); CompilerInstance &CI = getCompilerInstance(); bool Preamble = CI.getPreprocessorOpts().PrecompiledPreambleBytes.first != 0; const std::string &Sysroot = CI.getHeaderSearchOpts().Sysroot; @@ -658,6 +660,8 @@ } void PrintPreprocessedAction::ExecuteAction() { + llvm::NamedRegionTimer T("printpp", "Print PP actions", GroupName, + GroupDescription, llvm::TimePassesIsEnabled); CompilerInstance &CI = getCompilerInstance(); // Output file may need to be set to 'Binary', to avoid converting Unix style // line feeds () to Microsoft style line feeds (). Index: lib/Lex/HeaderSearch.cpp =================================================================== --- lib/Lex/HeaderSearch.cpp +++ lib/Lex/HeaderSearch.cpp @@ -30,11 +30,13 @@ #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Pass.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/Capacity.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" +#include "llvm/Support/Timer.h" #include #include #include @@ -199,6 +201,9 @@ } Module *HeaderSearch::lookupModule(StringRef ModuleName, bool AllowSearch) { + llvm::NamedRegionTimer T("lookupmodule", "Lookup Module", IncGroupName, + IncGroupDescription, llvm::TimePassesIsEnabled); + // Look in the module map to determine if there is a module by this name. Module *Module = ModMap.findModule(ModuleName); if (Module || !AllowSearch || !HSOpts->ImplicitModuleMaps) @@ -223,6 +228,8 @@ } Module *HeaderSearch::lookupModule(StringRef ModuleName, StringRef SearchName) { + llvm::NamedRegionTimer T("lookupmodule", "Lookup Module", IncGroupName, + IncGroupDescription, llvm::TimePassesIsEnabled); Module *Module = nullptr; // Look through the various header search paths to load any available module @@ -340,6 +347,8 @@ bool &InUserSpecifiedSystemFramework, bool &HasBeenMapped, SmallVectorImpl &MappedName) const { + llvm::NamedRegionTimer T("lookupfile", "Lookup File", IncGroupName, + IncGroupDescription, llvm::TimePassesIsEnabled); InUserSpecifiedSystemFramework = false; HasBeenMapped = false; @@ -467,6 +476,8 @@ SmallVectorImpl *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, bool &InUserSpecifiedSystemFramework) const { + llvm::NamedRegionTimer T("lookupfw", "Lookup Framework", IncGroupName, + IncGroupDescription, llvm::TimePassesIsEnabled); FileManager &FileMgr = HS.getFileMgr(); // Framework names must have a '/' in the filename. @@ -633,6 +644,8 @@ SmallVectorImpl *SearchPath, SmallVectorImpl *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, bool *IsMapped, bool SkipCache, bool BuildSystemModule) { + llvm::NamedRegionTimer T("lookupfile2", "Lookup File2", IncGroupName, + IncGroupDescription, llvm::TimePassesIsEnabled); if (IsMapped) *IsMapped = false; @@ -894,6 +907,8 @@ Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule) { assert(ContextFileEnt && "No context file?"); + llvm::NamedRegionTimer T("lookupsubfm", "Lookup SubFramework", IncGroupName, + IncGroupDescription, llvm::TimePassesIsEnabled); // Framework names must have a '/' in the filename. Find it. // FIXME: Should we permit '\' on Windows? @@ -1111,6 +1126,9 @@ bool HeaderSearch::ShouldEnterIncludeFile(Preprocessor &PP, const FileEntry *File, bool isImport, bool ModulesEnabled, Module *M) { + llvm::NamedRegionTimer T("shouldenterinc", "Should Enter Include File", + IncGroupName, IncGroupDescription, + llvm::TimePassesIsEnabled); ++NumIncluded; // Count # of attempted #includes. // Get information about this file. @@ -1287,6 +1305,9 @@ bool HeaderSearch::findUsableModuleForHeader( const FileEntry *File, const DirectoryEntry *Root, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, bool IsSystemHeaderDir) { + llvm::NamedRegionTimer T("findmodule4header", "Find Usable Module For Header", + IncGroupName, IncGroupDescription, + llvm::TimePassesIsEnabled); if (File && needModuleLookup(RequestingModule, SuggestedModule)) { // If there is a module that corresponds to this header, suggest it. hasModuleMap(File->getName(), Root, IsSystemHeaderDir); @@ -1299,6 +1320,9 @@ const FileEntry *File, StringRef FrameworkName, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, bool IsSystemFramework) { // If we're supposed to suggest a module, look for one now. + llvm::NamedRegionTimer T( + "findmodule4fwheader", "Find Usable Module For Framework Header", + IncGroupName, IncGroupDescription, llvm::TimePassesIsEnabled); if (needModuleLookup(RequestingModule, SuggestedModule)) { // Find the top-level framework based on this framework. SmallVector SubmodulePath; @@ -1483,6 +1507,8 @@ } void HeaderSearch::collectAllModules(SmallVectorImpl &Modules) { + llvm::NamedRegionTimer T("allmodules", "Collect All Modules", IncGroupName, + IncGroupDescription, llvm::TimePassesIsEnabled); Modules.clear(); if (HSOpts->ImplicitModuleMaps) { Index: lib/Lex/PPMacroExpansion.cpp =================================================================== --- lib/Lex/PPMacroExpansion.cpp +++ lib/Lex/PPMacroExpansion.cpp @@ -26,9 +26,9 @@ #include "clang/Lex/LexDiagnostic.h" #include "clang/Lex/MacroArgs.h" #include "clang/Lex/MacroInfo.h" +#include "clang/Lex/PTHLexer.h" #include "clang/Lex/Preprocessor.h" #include "clang/Lex/PreprocessorLexer.h" -#include "clang/Lex/PTHLexer.h" #include "clang/Lex/Token.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" @@ -36,15 +36,16 @@ #include "llvm/ADT/FoldingSet.h" #include "llvm/ADT/None.h" #include "llvm/ADT/Optional.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Config/llvm-config.h" #include "llvm/Support/Casting.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Format.h" +#include "llvm/Support/Timer.h" #include "llvm/Support/raw_ostream.h" #include #include @@ -57,6 +58,9 @@ using namespace clang; +static const char *const GroupName = "clangparser"; +static const char *const GroupDescription = "===== Clang Parser ====="; + MacroDirective * Preprocessor::getLocalMacroDirectiveHistory(const IdentifierInfo *II) const { if (!II->hadMacroDefinition()) @@ -69,6 +73,8 @@ void Preprocessor::appendMacroDirective(IdentifierInfo *II, MacroDirective *MD){ assert(MD && "MacroDirective should be non-zero!"); assert(!MD->getPrevious() && "Already attached to a MacroDirective history."); + llvm::NamedRegionTimer NRT("appendmacro", "PP Append Macro", GroupName, + GroupDescription, llvm::TimePassesIsEnabled); MacroState &StoredMD = CurSubmoduleState->Macros[II]; auto *OldMD = StoredMD.getLatest(); @@ -131,6 +137,8 @@ MacroInfo *Macro, ArrayRef Overrides, bool &New) { + llvm::NamedRegionTimer NRT("addmodulemacro", "PP Add Module Macro", GroupName, + GroupDescription, llvm::TimePassesIsEnabled); llvm::FoldingSetNodeID ID; ModuleMacro::Profile(ID, Mod, II); @@ -182,6 +190,9 @@ assert(Info.ActiveModuleMacrosGeneration != CurSubmoduleState->VisibleModules.getGeneration() && "don't need to update this macro name info"); + llvm::NamedRegionTimer NRT("updatemodulemacro", "PP Update Module Macro", + GroupName, GroupDescription, + llvm::TimePassesIsEnabled); Info.ActiveModuleMacrosGeneration = CurSubmoduleState->VisibleModules.getGeneration(); @@ -754,6 +765,8 @@ MacroArgs *Preprocessor::ReadMacroCallArgumentList(Token &MacroName, MacroInfo *MI, SourceLocation &MacroEnd) { + llvm::NamedRegionTimer NRT("clangparser30", "PP Macro Call Args", GroupName, + GroupDescription, llvm::TimePassesIsEnabled); // The number of fixed arguments to parse. unsigned NumFixedArgsLeft = MI->getNumParams(); bool isVariadic = MI->isVariadic(); Index: lib/Lex/Pragma.cpp =================================================================== --- lib/Lex/Pragma.cpp +++ lib/Lex/Pragma.cpp @@ -29,9 +29,9 @@ #include "clang/Lex/MacroInfo.h" #include "clang/Lex/ModuleLoader.h" #include "clang/Lex/PPCallbacks.h" +#include "clang/Lex/PTHLexer.h" #include "clang/Lex/Preprocessor.h" #include "clang/Lex/PreprocessorLexer.h" -#include "clang/Lex/PTHLexer.h" #include "clang/Lex/Token.h" #include "clang/Lex/TokenLexer.h" #include "llvm/ADT/ArrayRef.h" @@ -39,11 +39,13 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/StringSwitch.h" #include "llvm/ADT/StringRef.h" -#include "llvm/Support/CrashRecoveryContext.h" +#include "llvm/ADT/StringSwitch.h" +#include "llvm/Pass.h" #include "llvm/Support/Compiler.h" +#include "llvm/Support/CrashRecoveryContext.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/Timer.h" #include #include #include @@ -54,6 +56,8 @@ #include using namespace clang; +static const char *const GroupName = "clangparser"; +static const char *const GroupDescription = "===== Clang Parser ====="; // Out-of-line destructor to provide a home for the class. PragmaHandler::~PragmaHandler() = default; @@ -82,6 +86,8 @@ /// the null handler isn't returned on failure to match. PragmaHandler *PragmaNamespace::FindHandler(StringRef Name, bool IgnoreNull) const { + llvm::NamedRegionTimer NRT("clangparser22", "PP Find Handler", GroupName, + GroupDescription, llvm::TimePassesIsEnabled); if (PragmaHandler *Handler = Handlers.lookup(Name)) return Handler; return IgnoreNull ? nullptr : Handlers.lookup(StringRef()); @@ -128,6 +134,8 @@ /// rest of the pragma, passing it to the registered pragma handlers. void Preprocessor::HandlePragmaDirective(SourceLocation IntroducerLoc, PragmaIntroducerKind Introducer) { + llvm::NamedRegionTimer NRT("pppragma", "Handle Pragma Directive", GroupName, + GroupDescription, llvm::TimePassesIsEnabled); if (Callbacks) Callbacks->PragmaDirective(IntroducerLoc, Introducer); Index: lib/Parse/ParseTemplate.cpp =================================================================== --- lib/Parse/ParseTemplate.cpp +++ lib/Parse/ParseTemplate.cpp @@ -19,6 +19,7 @@ #include "clang/Sema/DeclSpec.h" #include "clang/Sema/ParsedTemplate.h" #include "clang/Sema/Scope.h" +#include "llvm/Support/Timer.h" using namespace clang; /// \brief Parse a template declaration, explicit instantiation, or @@ -28,6 +29,8 @@ SourceLocation &DeclEnd, AccessSpecifier AS, AttributeList *AccessAttrs) { + llvm::NamedRegionTimer NRT("clangparser10", "Parse Template", GroupName, + GroupDescription, llvm::TimePassesIsEnabled); ObjCDeclContextSwitch ObjCDC(*this); if (Tok.is(tok::kw_template) && NextToken().isNot(tok::less)) { Index: lib/Parse/Parser.cpp =================================================================== --- lib/Parse/Parser.cpp +++ lib/Parse/Parser.cpp @@ -20,6 +20,7 @@ #include "clang/Sema/DeclSpec.h" #include "clang/Sema/ParsedTemplate.h" #include "clang/Sema/Scope.h" +#include "llvm/Support/Timer.h" using namespace clang; @@ -368,6 +369,8 @@ /// ExitScope - Pop a scope off the scope stack. void Parser::ExitScope() { assert(getCurScope() && "Scope imbalance!"); + llvm::NamedRegionTimer NRT("clangparser5", "Scope manipulation", GroupName, + GroupDescription, llvm::TimePassesIsEnabled); // Inform the actions module that this scope is going away if there are any // decls in it. @@ -543,6 +546,9 @@ /// ParseTopLevelDecl - Parse one top-level declaration, return whatever the /// action tells us to. This returns true if the EOF was encountered. bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result) { + llvm::NamedRegionTimer NRT("ParseTopLevelDecl", "Parse Top Level Decl", + GroupName, GroupDescription, + llvm::TimePassesIsEnabled); DestroyTemplateIdAnnotationsRAIIObj CleanupRAII(TemplateIds); // Skip over the EOF token, flagging end of previous input for incremental @@ -1046,6 +1052,9 @@ Decl *Parser::ParseFunctionDefinition(ParsingDeclarator &D, const ParsedTemplateInfo &TemplateInfo, LateParsedAttrList *LateParsedAttrs) { + llvm::NamedRegionTimer NRT("parsefdef", "Parse Function Definition", + GroupName, GroupDescription, + llvm::TimePassesIsEnabled); // Poison SEH identifiers so they are flagged as illegal in function bodies. PoisonSEHIdentifiersRAIIObject PoisonSEHIdentifiers(*this, true); const DeclaratorChunk::FunctionTypeInfo &FTI = D.getFunctionTypeInfo(); @@ -1456,6 +1465,9 @@ /// declaration is finished. TemplateIdAnnotation *Parser::takeTemplateIdAnnotation(const Token &tok) { assert(tok.is(tok::annot_template_id) && "Expected template-id token"); + // llvm::NamedRegionTimer NRT("templateannotate", "Template Annotation + // operations", GroupName, + // GroupDescription, llvm::TimePassesIsEnabled); TemplateIdAnnotation * Id = static_cast(tok.getAnnotationValue()); return Id; @@ -1659,7 +1671,6 @@ Tok.is(tok::kw_decltype) || Tok.is(tok::annot_template_id) || Tok.is(tok::kw___super)) && "Cannot be a type or scope token!"); - if (Tok.is(tok::kw_typename)) { // MSVC lets you do stuff like: // typename typedef T_::D D; @@ -1881,6 +1892,9 @@ (Tok.is(tok::annot_template_id) && NextToken().is(tok::coloncolon)) || Tok.is(tok::kw_decltype) || Tok.is(tok::kw___super)) && "Cannot be a type or scope token!"); + // llvm::NamedRegionTimer NRT("clangparser7", "Annotation operations", + // GroupName, + // GroupDescription, llvm::TimePassesIsEnabled); CXXScopeSpec SS; if (ParseOptionalCXXScopeSpecifier(SS, nullptr, EnteringContext)) @@ -1922,6 +1936,9 @@ SourceLocation Parser::handleUnexpectedCodeCompletionToken() { assert(Tok.is(tok::code_completion)); + llvm::NamedRegionTimer NRT("clangparser8", "Code completion operations", + GroupName, GroupDescription, + llvm::TimePassesIsEnabled); PrevTokLocation = Tok.getLocation(); for (Scope *S = getCurScope(); S; S = S->getParent()) { @@ -1947,29 +1964,47 @@ // Code-completion pass-through functions void Parser::CodeCompleteDirective(bool InConditional) { + llvm::NamedRegionTimer NRT("clangparser8", "Code completion operations", + GroupName, GroupDescription, + llvm::TimePassesIsEnabled); Actions.CodeCompletePreprocessorDirective(InConditional); } void Parser::CodeCompleteInConditionalExclusion() { + llvm::NamedRegionTimer NRT("clangparser8", "Code completion operations", + GroupName, GroupDescription, + llvm::TimePassesIsEnabled); Actions.CodeCompleteInPreprocessorConditionalExclusion(getCurScope()); } void Parser::CodeCompleteMacroName(bool IsDefinition) { + llvm::NamedRegionTimer NRT("clangparser8", "Code completion operations", + GroupName, GroupDescription, + llvm::TimePassesIsEnabled); Actions.CodeCompletePreprocessorMacroName(IsDefinition); } -void Parser::CodeCompletePreprocessorExpression() { +void Parser::CodeCompletePreprocessorExpression() { + llvm::NamedRegionTimer NRT("clangparser8", "Code completion operations", + GroupName, GroupDescription, + llvm::TimePassesIsEnabled); Actions.CodeCompletePreprocessorExpression(); } void Parser::CodeCompleteMacroArgument(IdentifierInfo *Macro, MacroInfo *MacroInfo, unsigned ArgumentIndex) { + llvm::NamedRegionTimer NRT("clangparser8", "Code completion operations", + GroupName, GroupDescription, + llvm::TimePassesIsEnabled); Actions.CodeCompletePreprocessorMacroArgument(getCurScope(), Macro, MacroInfo, ArgumentIndex); } void Parser::CodeCompleteNaturalLanguage() { + llvm::NamedRegionTimer NRT("clangparser8", "Code completion operations", + GroupName, GroupDescription, + llvm::TimePassesIsEnabled); Actions.CodeCompleteNaturalLanguage(); } @@ -2078,6 +2113,9 @@ /// /// Note that 'partition' is a context-sensitive keyword. Parser::DeclGroupPtrTy Parser::ParseModuleDecl() { + llvm::NamedRegionTimer NRT("clangparser9", "Module related operations", + GroupName, GroupDescription, + llvm::TimePassesIsEnabled); SourceLocation StartLoc = Tok.getLocation(); Sema::ModuleDeclKind MDK = TryConsumeToken(tok::kw_export) @@ -2123,6 +2161,9 @@ assert((AtLoc.isInvalid() ? Tok.is(tok::kw_import) : Tok.isObjCAtKeyword(tok::objc_import)) && "Improper start to module import"); + llvm::NamedRegionTimer NRT("clangparser9", "Module related operations", + GroupName, GroupDescription, + llvm::TimePassesIsEnabled); SourceLocation ImportLoc = ConsumeToken(); SourceLocation StartLoc = AtLoc.isInvalid() ? ImportLoc : AtLoc; @@ -2160,6 +2201,9 @@ SourceLocation UseLoc, SmallVectorImpl> &Path, bool IsImport) { + llvm::NamedRegionTimer NRT("clangparser9", "Module related operations", + GroupName, GroupDescription, + llvm::TimePassesIsEnabled); // Parse the module path. while (true) { if (!Tok.is(tok::identifier)) { @@ -2190,6 +2234,9 @@ /// \returns false if the recover was successful and parsing may be continued, or /// true if parser must bail out to top level and handle the token there. bool Parser::parseMisplacedModuleImport() { + llvm::NamedRegionTimer NRT("clangparser9", "Module related operations", + GroupName, GroupDescription, + llvm::TimePassesIsEnabled); while (true) { switch (Tok.getKind()) { case tok::annot_module_end: Index: lib/Sema/Sema.cpp =================================================================== --- lib/Sema/Sema.cpp +++ lib/Sema/Sema.cpp @@ -40,6 +40,7 @@ #include "clang/Sema/TemplateInstCallback.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallSet.h" +#include "llvm/Support/Timer.h" using namespace clang; using namespace sema; @@ -842,6 +843,9 @@ /// translation unit when EOF is reached and all but the top-level scope is /// popped. void Sema::ActOnEndOfTranslationUnit() { + llvm::NamedRegionTimer T( + "ActOnEndOfTUnit", "Act On End Of Translation Unit: Common case", + GroupName, GroupDescription, llvm::TimePassesIsEnabled); assert(DelayedDiagnostics.getCurrentPool() == nullptr && "reached end of translation unit with a pool attached?"); @@ -853,6 +857,10 @@ // Complete translation units and modules define vtables and perform implicit // instantiations. PCH files do not. if (TUKind != TU_Prefix) { + llvm::NamedRegionTimer T( + "ActOnEndOfTranslationUnit", + "Act On End Of Translation Unit: TUKind != TU_Prefix", GroupName, + GroupDescription, llvm::TimePassesIsEnabled); DiagnoseUseOfUnimplementedSelectors(); // If DefinedUsedVTables ends up marking any virtual member functions it @@ -910,6 +918,10 @@ UnusedFileScopedDecls.end()); if (TUKind == TU_Prefix) { + llvm::NamedRegionTimer T( + "ActOnEndOfTranslationUnit", + "Act On End Of Translation Unit: TUKind == TU_Prefix", GroupName, + GroupDescription, llvm::TimePassesIsEnabled); // Translation unit prefixes don't need any of the checking below. if (!PP.isIncrementalProcessingEnabled()) TUScope = nullptr; @@ -944,6 +956,10 @@ } if (TUKind == TU_Module) { + llvm::NamedRegionTimer T( + "ActOnEndOfTranslationUnit", + "Act On End Of Translation Unit: TUKind == TU_Module", GroupName, + GroupDescription, llvm::TimePassesIsEnabled); // If we are building a module interface unit, we need to have seen the // module declaration by now. if (getLangOpts().getCompilingModule() == @@ -1544,6 +1560,9 @@ /// name, this parameter is populated with the decls of the various overloads. bool Sema::tryExprAsCall(Expr &E, QualType &ZeroArgCallReturnTy, UnresolvedSetImpl &OverloadSet) { + llvm::NamedRegionTimer T("tryExprAsCall", "Try Expr As Call", GroupName, + GroupDescription, llvm::TimePassesIsEnabled); + ZeroArgCallReturnTy = QualType(); OverloadSet.clear(); @@ -1706,6 +1725,9 @@ bool Sema::tryToRecoverWithCall(ExprResult &E, const PartialDiagnostic &PD, bool ForceComplain, bool (*IsPlausibleResult)(QualType)) { + llvm::NamedRegionTimer T("tryToRecoverWithCall", "Try To Recover With Call", + GroupName, GroupDescription, + llvm::TimePassesIsEnabled); SourceLocation Loc = E.get()->getExprLoc(); SourceRange Range = E.get()->getSourceRange(); Index: lib/Sema/SemaChecking.cpp =================================================================== --- lib/Sema/SemaChecking.cpp +++ lib/Sema/SemaChecking.cpp @@ -84,6 +84,7 @@ #include "llvm/Support/Format.h" #include "llvm/Support/Locale.h" #include "llvm/Support/MathExtras.h" +#include "llvm/Support/Timer.h" #include "llvm/Support/raw_ostream.h" #include #include @@ -118,7 +119,7 @@ // Highlight all the excess arguments. SourceRange range(call->getArg(desiredArgCount)->getLocStart(), call->getArg(argCount - 1)->getLocEnd()); - + return S.Diag(range.getBegin(), diag::err_typecheck_call_too_many_args) << 0 /*function call*/ << desiredArgCount << argCount << call->getArg(1)->getSourceRange(); @@ -224,7 +225,7 @@ } static void SemaBuiltinMemChkCall(Sema &S, FunctionDecl *FDecl, - CallExpr *TheCall, unsigned SizeIdx, + CallExpr *TheCall, unsigned SizeIdx, unsigned DstSizeIdx) { if (TheCall->getNumArgs() <= SizeIdx || TheCall->getNumArgs() <= DstSizeIdx) @@ -491,6 +492,9 @@ /// void (^block)(local void*, ...), /// uint size0, ...) static bool SemaOpenCLBuiltinEnqueueKernel(Sema &S, CallExpr *TheCall) { + llvm::NamedRegionTimer T( + "SemaOpenCLBuiltinEnqueueKernel", "Sema OpenCL Builtin Enqueue Kernel", + Sema::GroupName, Sema::GroupDescription, llvm::TimePassesIsEnabled); unsigned NumArgs = TheCall->getNumArgs(); if (NumArgs < 4) { @@ -853,6 +857,10 @@ ExprResult Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID, CallExpr *TheCall) { + llvm::NamedRegionTimer T("CheckBuiltinFunctionCall", + "Check Builtin Function Call", GroupName, + GroupDescription, llvm::TimePassesIsEnabled); + ExprResult TheCallResult(TheCall); // Find out if any arguments are required to be integer constant expressions. @@ -2259,6 +2267,9 @@ } bool Sema::CheckX86BuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { + llvm::NamedRegionTimer T("CheckX86BuiltinFunctionCall", + "Check X86 Builtin Function Call", GroupName, + GroupDescription, llvm::TimePassesIsEnabled); if (BuiltinID == X86::BI__builtin_cpu_supports) return SemaBuiltinCpuSupports(*this, TheCall); @@ -2699,6 +2710,8 @@ const Expr *ThisArg, ArrayRef Args, bool IsMemberFunction, SourceLocation Loc, SourceRange Range, VariadicCallType CallType) { + llvm::NamedRegionTimer T("checkCall", "Check Call", GroupName, + GroupDescription, llvm::TimePassesIsEnabled); // FIXME: We should check as much as we can in the template definition. if (CurContext->isDependentContext()) return; @@ -3337,6 +3350,10 @@ /// builtins, ExprResult Sema::SemaBuiltinAtomicOverloaded(ExprResult TheCallResult) { + llvm::NamedRegionTimer T("SemaBuiltinAtomicOverloaded", + "Sema Builtin Atomic Overloaded", GroupName, + GroupDescription, llvm::TimePassesIsEnabled); + CallExpr *TheCall = (CallExpr *)TheCallResult.get(); DeclRefExpr *DRE =cast(TheCall->getCallee()->IgnoreParenCasts()); FunctionDecl *FDecl = cast(DRE->getDecl()); @@ -9504,6 +9521,10 @@ static void CheckImplicitConversion(Sema &S, Expr *E, QualType T, SourceLocation CC, bool *ICContext = nullptr) { + llvm::NamedRegionTimer NRT("CheckImplicitConversion", + "Check Implicit Conversion", Sema::GroupName, + Sema::GroupDescription, llvm::TimePassesIsEnabled); + if (E->isTypeDependent() || E->isValueDependent()) return; const Type *Source = S.Context.getCanonicalType(E->getType()).getTypePtr(); @@ -9555,7 +9576,7 @@ return; return DiagnoseImpCast(S, E, T, CC, diag::warn_impcast_vector_scalar); } - + // If the vector cast is cast between two vectors of the same size, it is // a bitcast, not a conversion. if (S.Context.getTypeSize(Source) == S.Context.getTypeSize(Target)) Index: lib/Sema/SemaDecl.cpp =================================================================== --- lib/Sema/SemaDecl.cpp +++ lib/Sema/SemaDecl.cpp @@ -44,6 +44,7 @@ #include "clang/Sema/Template.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/Triple.h" +#include "llvm/Support/Timer.h" #include #include #include @@ -849,6 +850,8 @@ SourceLocation NameLoc, const Token &NextToken, bool IsAddressOfOperand, std::unique_ptr CCC) { + llvm::NamedRegionTimer T("ClassifyName", "Classify Name", GroupName, + GroupDescription, llvm::TimePassesIsEnabled); DeclarationNameInfo NameInfo(Name, NameLoc); ObjCMethodDecl *CurMethod = getCurMethodDecl(); @@ -5316,6 +5319,8 @@ NamedDecl *Sema::HandleDeclarator(Scope *S, Declarator &D, MultiTemplateParamsArg TemplateParamLists) { + llvm::NamedRegionTimer T("HandleDeclarator", "Handle Declarator", GroupName, + GroupDescription, llvm::TimePassesIsEnabled); // TODO: consider using NameInfo for diagnostic. DeclarationNameInfo NameInfo = GetNameForDeclarator(D); DeclarationName Name = NameInfo.getName(); Index: lib/Sema/SemaExpr.cpp =================================================================== --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -44,6 +44,7 @@ #include "clang/Sema/SemaInternal.h" #include "clang/Sema/Template.h" #include "llvm/Support/ConvertUTF.h" +#include "llvm/Support/Timer.h" using namespace clang; using namespace sema; @@ -1307,6 +1308,10 @@ Expr *ControllingExpr, ArrayRef ArgTypes, ArrayRef ArgExprs) { + llvm::NamedRegionTimer T("ActOnGenericSelectionExpr", + "Act On Generic Selection Expr", GroupName, + GroupDescription, llvm::TimePassesIsEnabled); + unsigned NumAssocs = ArgTypes.size(); assert(NumAssocs == ArgExprs.size()); @@ -1519,6 +1524,9 @@ ExprResult Sema::ActOnStringLiteral(ArrayRef StringToks, Scope *UDLScope) { assert(!StringToks.empty() && "Must have at least one string!"); + llvm::NamedRegionTimer T("ActOnStringLiteral", "Act On String Literal", + GroupName, GroupDescription, + llvm::TimePassesIsEnabled); StringLiteralParser Literal(StringToks, PP); if (Literal.hadError) @@ -2026,6 +2034,9 @@ bool IsInlineAsmIdentifier, Token *KeywordReplacement) { assert(!(IsAddressOfOperand && HasTrailingLParen) && "cannot be direct & operand and have a trailing lparen"); + llvm::NamedRegionTimer T("ActOnIdExpression", "Act On Id Expression", + GroupName, GroupDescription, + llvm::TimePassesIsEnabled); if (SS.isInvalid()) return ExprError(); @@ -3062,6 +3073,10 @@ } ExprResult Sema::ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind) { + llvm::NamedRegionTimer T("ActOnPredefinedExpr", "Act On Predefined Expr", + GroupName, GroupDescription, + llvm::TimePassesIsEnabled); + PredefinedExpr::IdentType IT; switch (Kind) { Index: lib/Sema/SemaTemplate.cpp =================================================================== --- lib/Sema/SemaTemplate.cpp +++ lib/Sema/SemaTemplate.cpp @@ -32,6 +32,7 @@ #include "llvm/ADT/SmallBitVector.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/Support/Timer.h" #include using namespace clang; @@ -303,6 +304,9 @@ QualType ObjectType, bool EnteringContext, bool &MemberOfUnknownSpecialization) { + llvm::NamedRegionTimer T("LookupTemplateName", "Lookup Template Name", + GroupName, GroupDescription, + llvm::TimePassesIsEnabled); // Determine where to perform name lookup MemberOfUnknownSpecialization = false; DeclContext *LookupCtx = nullptr; @@ -543,6 +547,9 @@ const DeclarationNameInfo &NameInfo, bool isAddressOfOperand, const TemplateArgumentListInfo *TemplateArgs) { + llvm::NamedRegionTimer T("ActOnDependentIdExpression", + "Act On Dependent Id Expression", GroupName, + GroupDescription, llvm::TimePassesIsEnabled); DeclContext *DC = getFunctionLevelDeclContext(); // C++11 [expr.prim.general]p12: Index: test/Frontend/ftime-report-template-decl.cpp =================================================================== --- test/Frontend/ftime-report-template-decl.cpp +++ test/Frontend/ftime-report-template-decl.cpp @@ -0,0 +1,147 @@ +// RUN: %clang %s -S -o - -ftime-report 2>&1 | FileCheck %s +// RUN: %clang %s -S -o - -fdelayed-template-parsing -DDELAYED_TEMPLATE_PARSING -ftime-report 2>&1 | FileCheck %s + +// Template function declarations +template +void foo(); +template +void foo(); + +// Template function definitions. +template +void foo() {} + +// Template class (forward) declarations +template +struct A; +template +struct b; +template +struct C; +template +struct D; + +// Forward declarations with default parameters? +template +class X1; +template +class X2; + +// Forward declarations w/template template parameters +template