From 0de18e72c607c1b52be2c60d45cf2f9fc3af4542 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Fri, 10 Jan 2025 19:25:18 -0800 Subject: -ftime-report: reorganize timers The code generation time is unclear in the -ftime-report output: * The two clang timers "Code Generation Time" and "LLVM IR Generation Time" are in the default group "Miscellaneous Ungrouped Timers". * There is also a "Clang front-end time" group, which actually includes code generation time. ``` ===-------------------------------------------------------------------------=== Miscellaneous Ungrouped Timers ===-------------------------------------------------------------------------=== ---User Time--- --System Time-- --User+System-- ---Wall Time--- --- Name --- 0.0611 ( 1.7%) 0.0099 ( 4.4%) 0.0710 ( 1.9%) 0.0713 ( 1.9%) LLVM IR Generation Time 3.5140 ( 98.3%) 0.2165 ( 95.6%) 3.7306 ( 98.1%) 3.7342 ( 98.1%) Code Generation Time 3.5751 (100.0%) 0.2265 (100.0%) 3.8016 (100.0%) 3.8055 (100.0%) Total ... ===-------------------------------------------------------------------------=== Clang front-end time report ===-------------------------------------------------------------------------=== Total Execution Time: 3.9108 seconds (3.9146 wall clock) ---User Time--- --System Time-- --User+System-- ---Wall Time--- --- Name --- 3.6802 (100.0%) 0.2306 (100.0%) 3.9108 (100.0%) 3.9146 (100.0%) Clang front-end timer 3.6802 (100.0%) 0.2306 (100.0%) 3.9108 (100.0%) 3.9146 (100.0%) Total ``` This patch * renames "Clang front-end time report" (FrontendAction time) to "Clang time report", * renames "Clang front-end" to "Front end", * moves "LLVM IR Generation" into the group, * replaces "Code Generation time" with "Optimizer" (middle end) and "Machine code generation" (back end). ``` % clang -c sqlite3.i -w -ftime-report -mllvm -sort-timers=0 ... ===-------------------------------------------------------------------------=== Clang time report ===-------------------------------------------------------------------------=== Total Execution Time: 1.5922 seconds (1.5972 wall clock) ---User Time--- --System Time-- --User+System-- ---Wall Time--- --- Name --- 0.5107 ( 35.9%) 0.0105 ( 6.2%) 0.5211 ( 32.7%) 0.5222 ( 32.7%) Front end 0.2464 ( 17.3%) 0.0340 ( 20.0%) 0.2804 ( 17.6%) 0.2814 ( 17.6%) LLVM IR generation 0.6240 ( 43.9%) 0.1235 ( 72.7%) 0.7475 ( 47.0%) 0.7503 ( 47.0%) Machine code generation 0.0413 ( 2.9%) 0.0018 ( 1.0%) 0.0431 ( 2.7%) 0.0433 ( 2.7%) Optimizer 1.4224 (100.0%) 0.1698 (100.0%) 1.5922 (100.0%) 1.5972 (100.0%) Total ``` Pull Request: https://github.com/llvm/llvm-project/pull/122225 --- clang/lib/CodeGen/CodeGenAction.cpp | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenAction.cpp') 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; } -- cgit v1.1