Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------------

Expand Down
4 changes: 3 additions & 1 deletion clang/include/clang/Frontend/CompilerInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -630,6 +630,8 @@ class CompilerInstance : public ModuleLoader {
/// @name Frontend timer
/// @{

llvm::TimerGroup &getTimerGroup() const { return *timerGroup; }

bool hasFrontendTimer() const { return (bool)FrontendTimer; }

llvm::Timer &getFrontendTimer() const {
Expand Down
19 changes: 15 additions & 4 deletions clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -208,7 +207,6 @@ class EmitAssemblyHelper {
: 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() {
Expand Down Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -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);
Expand Down
37 changes: 13 additions & 24 deletions clang/lib/CodeGen/CodeGenAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,16 @@ 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)),
LinkModules(std::move(LinkModules)), CurLinkModule(CurLinkModule) {
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 {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
24 changes: 10 additions & 14 deletions clang/lib/Frontend/CompilerInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions clang/test/Frontend/ftime-report-template-decl.cpp
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -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
3 changes: 3 additions & 0 deletions llvm/include/llvm/Support/Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ class Timer {
/// 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; }

Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/Support/Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 << " ----- ";
Expand Down
Loading