Skip to content

Commit dc3ded7

Browse files
committed
.
Created using spr 1.3.5-bogner
1 parent 97fdcb8 commit dc3ded7

File tree

5 files changed

+31
-29
lines changed

5 files changed

+31
-29
lines changed

clang/include/clang/Frontend/CompilerInstance.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class CompilerInstance : public ModuleLoader {
118118
std::unique_ptr<Sema> TheSema;
119119

120120
/// The frontend timer group.
121-
std::unique_ptr<llvm::TimerGroup> FrontendTimerGroup;
121+
std::unique_ptr<llvm::TimerGroup> timerGroup;
122122

123123
/// The frontend timer.
124124
std::unique_ptr<llvm::Timer> FrontendTimer;
@@ -630,9 +630,7 @@ class CompilerInstance : public ModuleLoader {
630630
/// @name Frontend timer
631631
/// @{
632632

633-
llvm::TimerGroup &getFrontendTimerGroup() const {
634-
return *FrontendTimerGroup;
635-
}
633+
llvm::TimerGroup &getTimerGroup() const { return *timerGroup; }
636634

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

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "clang/Frontend/FrontendDiagnostic.h"
1717
#include "clang/Frontend/Utils.h"
1818
#include "clang/Lex/HeaderSearchOptions.h"
19+
#include "llvm/ADT/ScopeExit.h"
1920
#include "llvm/ADT/StringExtras.h"
2021
#include "llvm/ADT/StringSwitch.h"
2122
#include "llvm/Analysis/GlobalsModRef.h"
@@ -1213,10 +1214,6 @@ void EmitAssemblyHelper::emitAssembly(const CompilerInstance &CI,
12131214
BackendAction Action,
12141215
std::unique_ptr<raw_pwrite_stream> OS,
12151216
BackendConsumer *BC) {
1216-
Timer timer;
1217-
if (CodeGenOpts.TimePasses)
1218-
timer.init("codegen", "Code Generation Time");
1219-
TimeRegion Region(CodeGenOpts.TimePasses ? &timer : nullptr);
12201217
setCommandLineOpts(CodeGenOpts);
12211218

12221219
bool RequiresCodeGen = actionRequiresCodeGen(Action);
@@ -1359,6 +1356,19 @@ void clang::emitBackendOutput(CompilerInstance &CI, StringRef TDesc,
13591356
const auto &TOpts = CI.getTargetOpts();
13601357
const auto &LOpts = CI.getLangOpts();
13611358

1359+
Timer timer;
1360+
if (CGOpts.TimePasses) {
1361+
CI.getFrontendTimer().stopTimer();
1362+
timer.init("backend", "Backend", CI.getTimerGroup());
1363+
timer.startTimer();
1364+
}
1365+
auto _ = llvm::make_scope_exit([&] {
1366+
if (!CGOpts.TimePasses)
1367+
return;
1368+
timer.stopTimer();
1369+
CI.getFrontendTimer().startTimer();
1370+
});
1371+
13621372
std::unique_ptr<llvm::Module> EmptyModule;
13631373
if (!CGOpts.ThinLTOIndexFile.empty()) {
13641374
// If we are performing a ThinLTO importing compile, load the function index

clang/lib/CodeGen/CodeGenAction.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ BackendConsumer::BackendConsumer(CompilerInstance &CI, BackendAction Action,
124124
llvm::TimePassesIsEnabled = CodeGenOpts.TimePasses;
125125
llvm::TimePassesPerRun = CodeGenOpts.TimePassesPerRun;
126126
if (CodeGenOpts.TimePasses)
127-
LLVMIRGeneration.init("irgen", "LLVM IR Generation Time",
128-
CI.getFrontendTimerGroup());
127+
LLVMIRGeneration.init("irgen", "LLVM IR Generation", CI.getTimerGroup());
129128
}
130129

131130
llvm::Module* BackendConsumer::getModule() const {

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -722,11 +722,9 @@ void CompilerInstance::createCodeCompletionConsumer() {
722722
}
723723

724724
void CompilerInstance::createFrontendTimer() {
725-
FrontendTimerGroup.reset(
726-
new llvm::TimerGroup("frontend", "Clang front-end time report"));
725+
timerGroup.reset(new llvm::TimerGroup("clang", "Clang time report"));
727726
FrontendTimer.reset(
728-
new llvm::Timer("frontend", "Clang front-end timer",
729-
*FrontendTimerGroup));
727+
new llvm::Timer("frontend", "Clang front-end", *timerGroup));
730728
}
731729

732730
CodeCompleteConsumer *
@@ -1726,10 +1724,9 @@ void CompilerInstance::createASTReader() {
17261724
const FrontendOptions &FEOpts = getFrontendOpts();
17271725
std::unique_ptr<llvm::Timer> ReadTimer;
17281726

1729-
if (FrontendTimerGroup)
1727+
if (timerGroup)
17301728
ReadTimer = std::make_unique<llvm::Timer>("reading_modules",
1731-
"Reading modules",
1732-
*FrontendTimerGroup);
1729+
"Reading modules", *timerGroup);
17331730
TheASTReader = new ASTReader(
17341731
getPreprocessor(), getModuleCache(), &getASTContext(),
17351732
getPCHContainerReader(), getFrontendOpts().ModuleFileExtensions,
@@ -1758,10 +1755,10 @@ void CompilerInstance::createASTReader() {
17581755
bool CompilerInstance::loadModuleFile(
17591756
StringRef FileName, serialization::ModuleFile *&LoadedModuleFile) {
17601757
llvm::Timer Timer;
1761-
if (FrontendTimerGroup)
1758+
if (timerGroup)
17621759
Timer.init("preloading." + FileName.str(), "Preloading " + FileName.str(),
1763-
*FrontendTimerGroup);
1764-
llvm::TimeRegion TimeLoading(FrontendTimerGroup ? &Timer : nullptr);
1760+
*timerGroup);
1761+
llvm::TimeRegion TimeLoading(timerGroup ? &Timer : nullptr);
17651762

17661763
// If we don't already have an ASTReader, create one now.
17671764
if (!TheASTReader)
@@ -1892,10 +1889,10 @@ ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST(
18921889

18931890
// Time how long it takes to load the module.
18941891
llvm::Timer Timer;
1895-
if (FrontendTimerGroup)
1892+
if (timerGroup)
18961893
Timer.init("loading." + ModuleFilename, "Loading " + ModuleFilename,
1897-
*FrontendTimerGroup);
1898-
llvm::TimeRegion TimeLoading(FrontendTimerGroup ? &Timer : nullptr);
1894+
*timerGroup);
1895+
llvm::TimeRegion TimeLoading(timerGroup ? &Timer : nullptr);
18991896
llvm::TimeTraceScope TimeScope("Module Load", ModuleName);
19001897

19011898
// Try to load the module file. If we are not trying to load from the

clang/test/Frontend/ftime-report-template-decl.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,8 @@ struct _Wrap_alloc {
150150
};
151151
_Wrap_alloc<int>::rebind<int> w;
152152

153-
// CHECK: Miscellaneous Ungrouped Timers
154-
// CHECK: Code Generation Time
155-
// CHECK: Total
156-
// CHECK: Clang front-end time report
157-
// CHECK: Clang front-end timer
158-
// CHECK-NEXT: LLVM IR Generation Time
153+
// CHECK: Clang time report
154+
// CHECK: Clang front-end
155+
// CHECK-NEXT: LLVM IR Generation
156+
// CHECK-NEXT: Backend
159157
// CHECK-NEXT: Total

0 commit comments

Comments
 (0)