diff options
-rw-r--r-- | clang/docs/ReleaseNotes.rst | 4 | ||||
-rw-r--r-- | clang/include/clang/Frontend/CompilerInstance.h | 4 | ||||
-rw-r--r-- | clang/lib/CodeGen/BackendUtil.cpp | 19 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenAction.cpp | 37 | ||||
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 24 | ||||
-rw-r--r-- | clang/test/Frontend/ftime-report-template-decl.cpp | 18 | ||||
-rw-r--r-- | llvm/include/llvm/Support/Timer.h | 3 | ||||
-rw-r--r-- | llvm/lib/Support/Timer.cpp | 5 |
8 files changed, 62 insertions, 52 deletions
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 190843f..197b369 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -445,6 +445,10 @@ Non-comprehensive list of changes in this release - Matrix types (a Clang extension) can now be used in pseudo-destructor expressions, which allows them to be stored in STL containers. +- In the ``-ftime-report`` output, the new "Clang time report" group replaces + the old "Clang front-end time report" and includes "Front end", "LLVM IR + generation", "Optimizer", and "Machine code generation". + New Compiler Flags ------------------ diff --git a/clang/include/clang/Frontend/CompilerInstance.h b/clang/include/clang/Frontend/CompilerInstance.h index 1220a4e..4a79b8d 100644 --- a/clang/include/clang/Frontend/CompilerInstance.h +++ b/clang/include/clang/Frontend/CompilerInstance.h @@ -118,7 +118,7 @@ class CompilerInstance : public ModuleLoader { std::unique_ptr<Sema> TheSema; /// The frontend timer group. - std::unique_ptr<llvm::TimerGroup> FrontendTimerGroup; + std::unique_ptr<llvm::TimerGroup> timerGroup; /// The frontend timer. std::unique_ptr<llvm::Timer> FrontendTimer; @@ -630,6 +630,8 @@ public: /// @name Frontend timer /// @{ + llvm::TimerGroup &getTimerGroup() const { return *timerGroup; } + bool hasFrontendTimer() const { return (bool)FrontendTimer; } llvm::Timer &getFrontendTimer() const { diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 2863887..bcf6db1 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -16,6 +16,7 @@ #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Frontend/Utils.h" #include "clang/Lex/HeaderSearchOptions.h" +#include "llvm/ADT/ScopeExit.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Analysis/GlobalsModRef.h" @@ -137,8 +138,6 @@ class EmitAssemblyHelper { llvm::Module *TheModule; IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS; - Timer CodeGenerationTime; - std::unique_ptr<raw_pwrite_stream> OS; Triple TargetTriple; @@ -208,7 +207,6 @@ public: : CI(CI), Diags(CI.getDiagnostics()), CodeGenOpts(CI.getCodeGenOpts()), TargetOpts(CI.getTargetOpts()), LangOpts(CI.getLangOpts()), TheModule(M), VFS(std::move(VFS)), - CodeGenerationTime("codegen", "Code Generation Time"), TargetTriple(TheModule->getTargetTriple()) {} ~EmitAssemblyHelper() { @@ -1157,7 +1155,14 @@ void EmitAssemblyHelper::RunOptimizationPipeline( { PrettyStackTraceString CrashInfo("Optimizer"); llvm::TimeTraceScope TimeScope("Optimizer"); + Timer timer; + if (CI.getCodeGenOpts().TimePasses) { + timer.init("optimizer", "Optimizer", CI.getTimerGroup()); + CI.getFrontendTimer().yieldTo(timer); + } MPM.run(*TheModule, MAM); + if (CI.getCodeGenOpts().TimePasses) + timer.yieldTo(CI.getFrontendTimer()); } } @@ -1200,14 +1205,20 @@ void EmitAssemblyHelper::RunCodegenPipeline( { PrettyStackTraceString CrashInfo("Code generation"); llvm::TimeTraceScope TimeScope("CodeGenPasses"); + Timer timer; + if (CI.getCodeGenOpts().TimePasses) { + timer.init("codegen", "Machine code generation", CI.getTimerGroup()); + CI.getFrontendTimer().yieldTo(timer); + } CodeGenPasses.run(*TheModule); + if (CI.getCodeGenOpts().TimePasses) + timer.yieldTo(CI.getFrontendTimer()); } } void EmitAssemblyHelper::emitAssembly(BackendAction Action, std::unique_ptr<raw_pwrite_stream> OS, BackendConsumer *BC) { - TimeRegion Region(CodeGenOpts.TimePasses ? &CodeGenerationTime : nullptr); setCommandLineOpts(CodeGenOpts); bool RequiresCodeGen = actionRequiresCodeGen(Action); diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index 7446bdd..15311fb 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -115,8 +115,7 @@ BackendConsumer::BackendConsumer(CompilerInstance &CI, BackendAction Action, llvm::Module *CurLinkModule) : CI(CI), Diags(CI.getDiagnostics()), CodeGenOpts(CI.getCodeGenOpts()), TargetOpts(CI.getTargetOpts()), LangOpts(CI.getLangOpts()), - AsmOutStream(std::move(OS)), FS(VFS), - LLVMIRGeneration("irgen", "LLVM IR Generation Time"), Action(Action), + AsmOutStream(std::move(OS)), FS(VFS), Action(Action), Gen(CreateLLVMCodeGen(Diags, InFile, std::move(VFS), CI.getHeaderSearchOpts(), CI.getPreprocessorOpts(), CI.getCodeGenOpts(), C, CoverageInfo)), @@ -124,6 +123,8 @@ BackendConsumer::BackendConsumer(CompilerInstance &CI, BackendAction Action, TimerIsEnabled = CodeGenOpts.TimePasses; llvm::TimePassesIsEnabled = CodeGenOpts.TimePasses; llvm::TimePassesPerRun = CodeGenOpts.TimePassesPerRun; + if (CodeGenOpts.TimePasses) + LLVMIRGeneration.init("irgen", "LLVM IR generation", CI.getTimerGroup()); } llvm::Module* BackendConsumer::getModule() const { @@ -162,19 +163,13 @@ bool BackendConsumer::HandleTopLevelDecl(DeclGroupRef D) { "LLVM IR generation of declaration"); // Recurse. - if (TimerIsEnabled) { - LLVMIRGenerationRefCount += 1; - if (LLVMIRGenerationRefCount == 1) - LLVMIRGeneration.startTimer(); - } + if (TimerIsEnabled && !LLVMIRGenerationRefCount++) + CI.getFrontendTimer().yieldTo(LLVMIRGeneration); Gen->HandleTopLevelDecl(D); - if (TimerIsEnabled) { - LLVMIRGenerationRefCount -= 1; - if (LLVMIRGenerationRefCount == 0) - LLVMIRGeneration.stopTimer(); - } + if (TimerIsEnabled && !--LLVMIRGenerationRefCount) + LLVMIRGeneration.yieldTo(CI.getFrontendTimer()); return true; } @@ -184,12 +179,12 @@ void BackendConsumer::HandleInlineFunctionDefinition(FunctionDecl *D) { Context->getSourceManager(), "LLVM IR generation of inline function"); if (TimerIsEnabled) - LLVMIRGeneration.startTimer(); + CI.getFrontendTimer().yieldTo(LLVMIRGeneration); Gen->HandleInlineFunctionDefinition(D); if (TimerIsEnabled) - LLVMIRGeneration.stopTimer(); + LLVMIRGeneration.yieldTo(CI.getFrontendTimer()); } void BackendConsumer::HandleInterestingDecl(DeclGroupRef D) { @@ -239,19 +234,13 @@ void BackendConsumer::HandleTranslationUnit(ASTContext &C) { { llvm::TimeTraceScope TimeScope("Frontend"); PrettyStackTraceString CrashInfo("Per-file LLVM IR generation"); - if (TimerIsEnabled) { - LLVMIRGenerationRefCount += 1; - if (LLVMIRGenerationRefCount == 1) - LLVMIRGeneration.startTimer(); - } + if (TimerIsEnabled && !LLVMIRGenerationRefCount++) + CI.getFrontendTimer().yieldTo(LLVMIRGeneration); Gen->HandleTranslationUnit(C); - if (TimerIsEnabled) { - LLVMIRGenerationRefCount -= 1; - if (LLVMIRGenerationRefCount == 0) - LLVMIRGeneration.stopTimer(); - } + if (TimerIsEnabled && !--LLVMIRGenerationRefCount) + LLVMIRGeneration.yieldTo(CI.getFrontendTimer()); IRGenFinished = true; } diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index fbfc305..b00a4ac 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -722,11 +722,8 @@ void CompilerInstance::createCodeCompletionConsumer() { } void CompilerInstance::createFrontendTimer() { - FrontendTimerGroup.reset( - new llvm::TimerGroup("frontend", "Clang front-end time report")); - FrontendTimer.reset( - new llvm::Timer("frontend", "Clang front-end timer", - *FrontendTimerGroup)); + timerGroup.reset(new llvm::TimerGroup("clang", "Clang time report")); + FrontendTimer.reset(new llvm::Timer("frontend", "Front end", *timerGroup)); } CodeCompleteConsumer * @@ -1726,10 +1723,9 @@ void CompilerInstance::createASTReader() { const FrontendOptions &FEOpts = getFrontendOpts(); std::unique_ptr<llvm::Timer> ReadTimer; - if (FrontendTimerGroup) + if (timerGroup) ReadTimer = std::make_unique<llvm::Timer>("reading_modules", - "Reading modules", - *FrontendTimerGroup); + "Reading modules", *timerGroup); TheASTReader = new ASTReader( getPreprocessor(), getModuleCache(), &getASTContext(), getPCHContainerReader(), getFrontendOpts().ModuleFileExtensions, @@ -1758,10 +1754,10 @@ void CompilerInstance::createASTReader() { bool CompilerInstance::loadModuleFile( StringRef FileName, serialization::ModuleFile *&LoadedModuleFile) { llvm::Timer Timer; - if (FrontendTimerGroup) + if (timerGroup) Timer.init("preloading." + FileName.str(), "Preloading " + FileName.str(), - *FrontendTimerGroup); - llvm::TimeRegion TimeLoading(FrontendTimerGroup ? &Timer : nullptr); + *timerGroup); + llvm::TimeRegion TimeLoading(timerGroup ? &Timer : nullptr); // If we don't already have an ASTReader, create one now. if (!TheASTReader) @@ -1892,10 +1888,10 @@ ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST( // Time how long it takes to load the module. llvm::Timer Timer; - if (FrontendTimerGroup) + if (timerGroup) Timer.init("loading." + ModuleFilename, "Loading " + ModuleFilename, - *FrontendTimerGroup); - llvm::TimeRegion TimeLoading(FrontendTimerGroup ? &Timer : nullptr); + *timerGroup); + llvm::TimeRegion TimeLoading(timerGroup ? &Timer : nullptr); llvm::TimeTraceScope TimeScope("Module Load", ModuleName); // Try to load the module file. If we are not trying to load from the diff --git a/clang/test/Frontend/ftime-report-template-decl.cpp b/clang/test/Frontend/ftime-report-template-decl.cpp index 9ba9107..45ce0dc 100644 --- a/clang/test/Frontend/ftime-report-template-decl.cpp +++ b/clang/test/Frontend/ftime-report-template-decl.cpp @@ -1,5 +1,6 @@ -// RUN: %clang_cc1 %s -emit-llvm -o - -ftime-report 2>&1 | FileCheck %s -// RUN: %clang_cc1 %s -emit-llvm -o - -fdelayed-template-parsing -DDELAYED_TEMPLATE_PARSING -ftime-report 2>&1 | FileCheck %s +// REQUIRES: x86-registered-target +// RUN: %clang_cc1 %s -S -triple=x86_64 -mllvm -sort-timers=0 -o - -ftime-report 2>&1 | FileCheck %s +// RUN: %clang_cc1 %s -S -triple=x86_64 -mllvm -sort-timers=0 -o - -fdelayed-template-parsing -DDELAYED_TEMPLATE_PARSING -ftime-report 2>&1 | FileCheck %s // Template function declarations template <typename T> @@ -150,10 +151,9 @@ struct _Wrap_alloc { }; _Wrap_alloc<int>::rebind<int> w; -// CHECK: Miscellaneous Ungrouped Timers -// CHECK-DAG: LLVM IR Generation Time -// CHECK-DAG: Code Generation Time -// CHECK: Total -// CHECK: Clang front-end time report -// CHECK: Clang front-end timer -// CHECK: Total +// CHECK: Clang time report +// CHECK: Front end +// CHECK-NEXT: LLVM IR generation +// CHECK-NEXT: Machine code generation +// CHECK-NEXT: Optimizer +// CHECK-NEXT: Total diff --git a/llvm/include/llvm/Support/Timer.h b/llvm/include/llvm/Support/Timer.h index d218599..abe3045 100644 --- a/llvm/include/llvm/Support/Timer.h +++ b/llvm/include/llvm/Support/Timer.h @@ -131,6 +131,9 @@ public: /// Clear the timer state. void clear(); + /// Stop the timer and start another timer. + void yieldTo(Timer &); + /// Return the duration for which this timer has been running. TimeRecord getTotalTime() const { return Time; } diff --git a/llvm/lib/Support/Timer.cpp b/llvm/lib/Support/Timer.cpp index 1fa2cdf..fbf3bec 100644 --- a/llvm/lib/Support/Timer.cpp +++ b/llvm/lib/Support/Timer.cpp @@ -166,6 +166,11 @@ void Timer::clear() { Time = StartTime = TimeRecord(); } +void Timer::yieldTo(Timer &O) { + stopTimer(); + O.startTimer(); +} + static void printVal(double Val, double Total, raw_ostream &OS) { if (Total < 1e-7) // Avoid dividing by zero. OS << " ----- "; |