[PATCH] D122759: [time-report] Add timers to codegen actions
weiwang updated this revision to Diff 419261. weiwang added a comment. fix typo Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D122759/new/ https://reviews.llvm.org/D122759 Files: clang/include/clang/Frontend/FrontendAction.h clang/include/clang/Parse/ParseAST.h clang/lib/CodeGen/BackendUtil.cpp clang/lib/CodeGen/CodeGenAction.cpp clang/lib/Frontend/FrontendAction.cpp clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp clang/lib/Parse/ParseAST.cpp Index: clang/lib/Parse/ParseAST.cpp === --- clang/lib/Parse/ParseAST.cpp +++ clang/lib/Parse/ParseAST.cpp @@ -23,6 +23,7 @@ #include "clang/Sema/TemplateInstCallback.h" #include "llvm/Support/CrashRecoveryContext.h" #include "llvm/Support/TimeProfiler.h" +#include "llvm/Support/Timer.h" #include #include @@ -111,7 +112,8 @@ ParseAST(*S.get(), PrintStats, SkipFunctionBodies); } -void clang::ParseAST(Sema , bool PrintStats, bool SkipFunctionBodies) { +void clang::ParseAST(Sema , bool PrintStats, bool SkipFunctionBodies, + bool TimePassesIsEnabled) { // Collect global stats on Decls/Stmts (until we have a module streamer). if (PrintStats) { Decl::EnableStatistics(); @@ -152,6 +154,8 @@ if (HaveLexer) { llvm::TimeTraceScope TimeScope("Frontend"); +llvm::NamedRegionTimer T("Parse AST", "Parse AST", "Clang Compilation", + "Clang Compilation", TimePassesIsEnabled); P.Initialize(); Parser::DeclGroupPtrTy ADecl; Sema::ModuleImportState ImportState; Index: clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp === --- clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp +++ clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp @@ -186,6 +186,9 @@ Act = std::make_unique(std::move(Act), FEOpts.ASTMergeFiles); + if (CI.getCodeGenOpts().TimePasses) +Act->enableTimePasses(); + return Act; } Index: clang/lib/Frontend/FrontendAction.cpp === --- clang/lib/Frontend/FrontendAction.cpp +++ clang/lib/Frontend/FrontendAction.cpp @@ -1137,7 +1137,7 @@ CI.createSema(getTranslationUnitKind(), CompletionConsumer); ParseAST(CI.getSema(), CI.getFrontendOpts().ShowStats, - CI.getFrontendOpts().SkipFunctionBodies); + CI.getFrontendOpts().SkipFunctionBodies, isTimePassesEnabled()); } void PluginASTAction::anchor() { } Index: clang/lib/CodeGen/CodeGenAction.cpp === --- clang/lib/CodeGen/CodeGenAction.cpp +++ clang/lib/CodeGen/CodeGenAction.cpp @@ -294,6 +294,9 @@ void HandleTranslationUnit(ASTContext ) override { { llvm::TimeTraceScope TimeScope("Frontend"); +llvm::NamedRegionTimer T("IR Generation", "IR Generation", + "Clang Compilation", "Clang Compilation", + CodeGenOpts.TimePasses); PrettyStackTraceString CrashInfo("Per-file LLVM IR generation"); if (TimerIsEnabled) { LLVMIRGenerationRefCount += 1; Index: clang/lib/CodeGen/BackendUtil.cpp === --- clang/lib/CodeGen/BackendUtil.cpp +++ clang/lib/CodeGen/BackendUtil.cpp @@ -1500,6 +1500,8 @@ { PrettyStackTraceString CrashInfo("Optimizer"); llvm::TimeTraceScope TimeScope("Optimizer"); +llvm::NamedRegionTimer T("Optimizer", "Optimizer", "Clang Compilation", + "Clang Compilation", CodeGenOpts.TimePasses); MPM.run(*TheModule, MAM); } } @@ -1536,6 +1538,9 @@ { PrettyStackTraceString CrashInfo("Code generation"); llvm::TimeTraceScope TimeScope("CodeGenPasses"); +llvm::NamedRegionTimer T("CodeGenPasses", "CodeGenPasses", + "Clang Compilation", "Clang Compilation", + CodeGenOpts.TimePasses); CodeGenPasses.run(*TheModule); } } Index: clang/include/clang/Parse/ParseAST.h === --- clang/include/clang/Parse/ParseAST.h +++ clang/include/clang/Parse/ParseAST.h @@ -44,7 +44,8 @@ /// Parse the main file known to the preprocessor, producing an /// abstract syntax tree. void ParseAST(Sema , bool PrintStats = false, -bool SkipFunctionBodies = false); +bool SkipFunctionBodies = false, +bool TimePassesIsEnabled = false); } // end namespace clang Index: clang/include/clang/Frontend/FrontendAction.h === --- clang/include/clang/Frontend/FrontendAction.h +++ clang/include/clang/Frontend/FrontendAction.h @@ -37,6 +37,7 @@ FrontendInputFile CurrentInput;
[PATCH] D122759: [time-report] Add timers to codegen actions
weiwang created this revision. Herald added subscribers: ormris, hoy, wenlei. Herald added a project: All. weiwang requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D122759 Files: clang/include/clang/Frontend/FrontendAction.h clang/include/clang/Parse/ParseAST.h clang/lib/CodeGen/BackendUtil.cpp clang/lib/CodeGen/CodeGenAction.cpp clang/lib/Frontend/FrontendAction.cpp clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp clang/lib/Parse/ParseAST.cpp Index: clang/lib/Parse/ParseAST.cpp === --- clang/lib/Parse/ParseAST.cpp +++ clang/lib/Parse/ParseAST.cpp @@ -23,6 +23,7 @@ #include "clang/Sema/TemplateInstCallback.h" #include "llvm/Support/CrashRecoveryContext.h" #include "llvm/Support/TimeProfiler.h" +#include "llvm/Support/Timer.h" #include #include @@ -111,7 +112,8 @@ ParseAST(*S.get(), PrintStats, SkipFunctionBodies); } -void clang::ParseAST(Sema , bool PrintStats, bool SkipFunctionBodies) { +void clang::ParseAST(Sema , bool PrintStats, bool SkipFunctionBodies, + bool TimePassesIsEnabled) { // Collect global stats on Decls/Stmts (until we have a module streamer). if (PrintStats) { Decl::EnableStatistics(); @@ -152,6 +154,8 @@ if (HaveLexer) { llvm::TimeTraceScope TimeScope("Frontend"); +llvm::NamedRegionTimer T("Parse AST", "Parse AST", "Clang Compilation", + "Clang Commpilation", TimePassesIsEnabled); P.Initialize(); Parser::DeclGroupPtrTy ADecl; Sema::ModuleImportState ImportState; Index: clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp === --- clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp +++ clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp @@ -186,6 +186,9 @@ Act = std::make_unique(std::move(Act), FEOpts.ASTMergeFiles); + if (CI.getCodeGenOpts().TimePasses) +Act->enableTimePasses(); + return Act; } Index: clang/lib/Frontend/FrontendAction.cpp === --- clang/lib/Frontend/FrontendAction.cpp +++ clang/lib/Frontend/FrontendAction.cpp @@ -1137,7 +1137,7 @@ CI.createSema(getTranslationUnitKind(), CompletionConsumer); ParseAST(CI.getSema(), CI.getFrontendOpts().ShowStats, - CI.getFrontendOpts().SkipFunctionBodies); + CI.getFrontendOpts().SkipFunctionBodies, isTimePassesEnabled()); } void PluginASTAction::anchor() { } Index: clang/lib/CodeGen/CodeGenAction.cpp === --- clang/lib/CodeGen/CodeGenAction.cpp +++ clang/lib/CodeGen/CodeGenAction.cpp @@ -294,6 +294,9 @@ void HandleTranslationUnit(ASTContext ) override { { llvm::TimeTraceScope TimeScope("Frontend"); +llvm::NamedRegionTimer T("IR Generation", "IR Generation", + "Clang Compilation", "Clang Compilation", + CodeGenOpts.TimePasses); PrettyStackTraceString CrashInfo("Per-file LLVM IR generation"); if (TimerIsEnabled) { LLVMIRGenerationRefCount += 1; Index: clang/lib/CodeGen/BackendUtil.cpp === --- clang/lib/CodeGen/BackendUtil.cpp +++ clang/lib/CodeGen/BackendUtil.cpp @@ -1500,6 +1500,8 @@ { PrettyStackTraceString CrashInfo("Optimizer"); llvm::TimeTraceScope TimeScope("Optimizer"); +llvm::NamedRegionTimer T("Optimizer", "Optimizer", "Clang Compilation", + "Clang Compilation", CodeGenOpts.TimePasses); MPM.run(*TheModule, MAM); } } @@ -1536,6 +1538,9 @@ { PrettyStackTraceString CrashInfo("Code generation"); llvm::TimeTraceScope TimeScope("CodeGenPasses"); +llvm::NamedRegionTimer T("CodeGenPasses", "CodeGenPasses", + "Clang Compilation", "Clang Compilation", + CodeGenOpts.TimePasses); CodeGenPasses.run(*TheModule); } } Index: clang/include/clang/Parse/ParseAST.h === --- clang/include/clang/Parse/ParseAST.h +++ clang/include/clang/Parse/ParseAST.h @@ -44,7 +44,8 @@ /// Parse the main file known to the preprocessor, producing an /// abstract syntax tree. void ParseAST(Sema , bool PrintStats = false, -bool SkipFunctionBodies = false); +bool SkipFunctionBodies = false, +bool TimePassesIsEnabled = false); } // end namespace clang Index: clang/include/clang/Frontend/FrontendAction.h === --- clang/include/clang/Frontend/FrontendAction.h +++