diff options
author | Fangrui Song <i@maskray.me> | 2025-01-10 19:25:18 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-10 19:25:18 -0800 |
commit | 0de18e72c607c1b52be2c60d45cf2f9fc3af4542 (patch) | |
tree | 573b0ec23d72e7765236a997d963ebe797a2c8ef /clang/lib/CodeGen/CodeGenAction.cpp | |
parent | df808df8f73e30d288e4dfdef5e527bc392f3bce (diff) | |
download | llvm-0de18e72c607c1b52be2c60d45cf2f9fc3af4542.zip llvm-0de18e72c607c1b52be2c60d45cf2f9fc3af4542.tar.gz llvm-0de18e72c607c1b52be2c60d45cf2f9fc3af4542.tar.bz2 |
-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
Diffstat (limited to 'clang/lib/CodeGen/CodeGenAction.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenAction.cpp | 37 |
1 files changed, 13 insertions, 24 deletions
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; } |