From df494f7512b0ecebdf3d7be97695a1b6278c0336 Mon Sep 17 00:00:00 2001 From: Russell Gallop Date: Wed, 11 Dec 2019 11:49:42 +0000 Subject: [PATCH] [Support] Add TimeTraceScope constructor without detail arg This simplifies code where no extra details are required Also don't write out detail when it is empty. Differential Revision: https://reviews.llvm.org/D71347 --- clang/lib/CodeGen/BackendUtil.cpp | 8 ++++---- clang/lib/CodeGen/CodeGenAction.cpp | 2 +- clang/lib/Parse/ParseAST.cpp | 2 +- clang/lib/Sema/Sema.cpp | 3 +-- clang/lib/Serialization/GlobalModuleIndex.cpp | 4 ++-- clang/tools/driver/cc1_main.cpp | 2 +- llvm/include/llvm/Support/TimeProfiler.h | 4 ++++ llvm/lib/Support/TimeProfiler.cpp | 4 +++- 8 files changed, 17 insertions(+), 12 deletions(-) diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index a226166..c54d15d 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -896,7 +896,7 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action, { PrettyStackTraceString CrashInfo("Per-function optimization"); - llvm::TimeTraceScope TimeScope("PerFunctionPasses", StringRef("")); + llvm::TimeTraceScope TimeScope("PerFunctionPasses"); PerFunctionPasses.doInitialization(); for (Function &F : *TheModule) @@ -907,13 +907,13 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action, { PrettyStackTraceString CrashInfo("Per-module optimization passes"); - llvm::TimeTraceScope TimeScope("PerModulePasses", StringRef("")); + llvm::TimeTraceScope TimeScope("PerModulePasses"); PerModulePasses.run(*TheModule); } { PrettyStackTraceString CrashInfo("Code generation"); - llvm::TimeTraceScope TimeScope("CodeGenPasses", StringRef("")); + llvm::TimeTraceScope TimeScope("CodeGenPasses"); CodeGenPasses.run(*TheModule); } @@ -1499,7 +1499,7 @@ void clang::EmitBackendOutput(DiagnosticsEngine &Diags, BackendAction Action, std::unique_ptr OS) { - llvm::TimeTraceScope TimeScope("Backend", StringRef("")); + llvm::TimeTraceScope TimeScope("Backend"); std::unique_ptr EmptyModule; if (!CGOpts.ThinLTOIndexFile.empty()) { diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index 1fa1f62..7f3f358 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -249,7 +249,7 @@ namespace clang { void HandleTranslationUnit(ASTContext &C) override { { - llvm::TimeTraceScope TimeScope("Frontend", StringRef("")); + llvm::TimeTraceScope TimeScope("Frontend"); PrettyStackTraceString CrashInfo("Per-file LLVM IR generation"); if (FrontendTimesIsEnabled) { LLVMIRGenerationRefCount += 1; diff --git a/clang/lib/Parse/ParseAST.cpp b/clang/lib/Parse/ParseAST.cpp index 3efd893..01510e8 100644 --- a/clang/lib/Parse/ParseAST.cpp +++ b/clang/lib/Parse/ParseAST.cpp @@ -151,7 +151,7 @@ void clang::ParseAST(Sema &S, bool PrintStats, bool SkipFunctionBodies) { bool HaveLexer = S.getPreprocessor().getCurrentLexer(); if (HaveLexer) { - llvm::TimeTraceScope TimeScope("Frontend", StringRef("")); + llvm::TimeTraceScope TimeScope("Frontend"); P.Initialize(); Parser::DeclGroupPtrTy ADecl; for (bool AtEOF = P.ParseFirstTopLevelDecl(ADecl); !AtEOF; diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index 8d59729..c5bf6fe 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -924,8 +924,7 @@ void Sema::ActOnEndOfTranslationUnitFragment(TUFragmentKind Kind) { } { - llvm::TimeTraceScope TimeScope("PerformPendingInstantiations", - StringRef("")); + llvm::TimeTraceScope TimeScope("PerformPendingInstantiations"); PerformPendingInstantiations(); } diff --git a/clang/lib/Serialization/GlobalModuleIndex.cpp b/clang/lib/Serialization/GlobalModuleIndex.cpp index dddee77..89a1c6c 100644 --- a/clang/lib/Serialization/GlobalModuleIndex.cpp +++ b/clang/lib/Serialization/GlobalModuleIndex.cpp @@ -134,7 +134,7 @@ GlobalModuleIndex::GlobalModuleIndex(std::unique_ptr Buffer, "' failed: " + toString(std::move(Err))); }; - llvm::TimeTraceScope TimeScope("Module LoadIndex", StringRef("")); + llvm::TimeTraceScope TimeScope("Module LoadIndex"); // Read the global index. bool InGlobalIndexBlock = false; bool Done = false; @@ -770,7 +770,7 @@ bool GlobalModuleIndexBuilder::writeIndex(llvm::BitstreamWriter &Stream) { } using namespace llvm; - llvm::TimeTraceScope TimeScope("Module WriteIndex", StringRef("")); + llvm::TimeTraceScope TimeScope("Module WriteIndex"); // Emit the file header. Stream.Emit((unsigned)'B', 8); diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp index efafed10..2b82a43 100644 --- a/clang/tools/driver/cc1_main.cpp +++ b/clang/tools/driver/cc1_main.cpp @@ -246,7 +246,7 @@ int cc1_main(ArrayRef Argv, const char *Argv0, void *MainAddr) { // Execute the frontend actions. { - llvm::TimeTraceScope TimeScope("ExecuteCompiler", StringRef("")); + llvm::TimeTraceScope TimeScope("ExecuteCompiler"); Success = ExecuteCompilerInvocation(Clang.get()); } diff --git a/llvm/include/llvm/Support/TimeProfiler.h b/llvm/include/llvm/Support/TimeProfiler.h index 2b51bba..678f8c1 100644 --- a/llvm/include/llvm/Support/TimeProfiler.h +++ b/llvm/include/llvm/Support/TimeProfiler.h @@ -58,6 +58,10 @@ struct TimeTraceScope { TimeTraceScope(TimeTraceScope &&) = delete; TimeTraceScope &operator=(TimeTraceScope &&) = delete; + TimeTraceScope(StringRef Name) { + if (TimeTraceProfilerInstance != nullptr) + timeTraceProfilerBegin(Name, StringRef("")); + } TimeTraceScope(StringRef Name, StringRef Detail) { if (TimeTraceProfilerInstance != nullptr) timeTraceProfilerBegin(Name, Detail); diff --git a/llvm/lib/Support/TimeProfiler.cpp b/llvm/lib/Support/TimeProfiler.cpp index 6c99338..a7c8550 100644 --- a/llvm/lib/Support/TimeProfiler.cpp +++ b/llvm/lib/Support/TimeProfiler.cpp @@ -123,7 +123,9 @@ struct TimeTraceProfiler { J.attribute("ts", StartUs); J.attribute("dur", DurUs); J.attribute("name", E.Name); - J.attributeObject("args", [&] { J.attribute("detail", E.Detail); }); + if (!E.Detail.empty()) { + J.attributeObject("args", [&] { J.attribute("detail", E.Detail); }); + } }); } -- 2.7.4